Forum rules - please read before posting.

Inventory items swap places

Hi! Sorry to spam the forum at the moment - I still have a few threads to answer.

In the meantime, I'm trying to make inventory items swap places when you drag them onto each other.

I thought that's what the Action List - Iventory Replace was for but it doesn't seem to work that way.
I also noticed that the Puzzle Arranging items example lets you do it with hotspots - but is it possible to do in the Inventory?

Many thanks

Comments

  • The built-in behaviour of dropping one item on another is to combine them. If no combine interaction exists, you should be able to hook into the OnInventoryCombine custom event to alter their positions in Player's Inventory collection.

    Something along these lines:

    using UnityEngine;
    using AC;
    
    public class ItemSwapper : MonoBehaviour
    {
    
        void OnEnable () { EventManager.OnInventoryCombine_Alt += OnInventoryCombine; }
        void OnDisable () { EventManager.OnInventoryCombine_Alt -= OnInventoryCombine; }
    
        void OnInventoryCombine (InvInstance invInstanceA, InvInstance invInstanceB)
        {
            var invCollection = KickStarter.runtimeInventory.playerInvCollection;
            int indexA = invCollection.IndexOf (invInstanceA);
            int indexB = invCollection.IndexOf (invInstanceB);
    
            invCollection.Insert (invInstanceA, indexB, OccupiedSlotBehaviour.Overwrite);
            invCollection.Insert (invInstanceB, indexA, OccupiedSlotBehaviour.Overwrite);
            PlayerMenus.ResetInventoryBoxes ();
        }
    
    }
    
  • It works great!

    All I had to do was make InvCollection playerInvCollection public in RuntimeInventory.cs

    Thanks so much!

  • No need for that - replace the script's use of it with PlayerInvCollection

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.