Forum rules - please read before posting.

Suggestion: Action to change places of inventory items

Unless I'm missing something, I can't change the position of an item in the inventory.
It would be nice to have an action for this.

The scenario is that some of my inventory items can be used in specialized ways and I would like to each other, though not necessarily first or last (where I keep special items like journal etc.).

Thanks

Comments

  • To group each other?

    Since placing an item at a specific point typically involves checking other conditions to determine where exactly to place it, this is best handled through custom scripting.

    You can use the Insert function to specify the index at which an item is inserted:

    InvInstance myItemInstance = new InvInstance ("ItemName");
    int newIndex = 2;
    KickStarter.player.Inventory.Insert (myItemInstance, newIndex);
    
  • edited August 2022

    Hmm, I'm not adding a new item but trying to shift an existing one.
    Could you perhaps clarify how to do that?
    I tried to first delete it and then re-add it, but deleting an ItemInstance didn't really do what I thought it would - I'm not sure how the two collections (InvInstances and InvItems) relate to one another.

    Also, I suppose something is needed to repaint the MenuInventoryBox afterwards?

  • I tried to first delete it and then re-add it, but deleting an ItemInstance didn't really do what I thought it would

    Deleting and re-adding it would be the way to go - what did it do?

    I'm not sure how the two collections (InvInstances and InvItems) relate to one another.

    An InvInstance is a runtime reference to an InvItem - similar to how a scene instance of a prefab references a prefab asset file.

    If a given item is present in multiple slots in your Inventory, then they'll all be linked to the same InvItem. Their InvInstances, however, will all be individual - so if you deal with InvInstances then it'll always be clear to AC exactly which slot you're referring to.

    More details on this can be found here.

    Also, I suppose something is needed to repaint the MenuInventoryBox afterwards?

    Yes, you'll need to manually update Inventory menus afterwards for the changes to be reflected your UI:

    AC.PlayerMenus.ResetInventoryBoxes ();
    
  • edited August 2022

    I managed to solve it like this:

    var itemInstance = KickStarter.player.Inventory.GetFirstInstance(itemId);
    KickStarter.player.Inventory.InvInstances.Remove(itemInstance);
    KickStarter.player.Inventory.Insert(itemInstance, newIndex);
    PlayerMenus.ResetInventoryBoxes();
    
    // Somewhat surprisingly, this removes one item from InvItems but doesn't change the InvInstances collection
    KickStarter.player.Inventory.Remove(itemInstance);
    

    Thanks

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.