Forum rules - please read before posting.

Close Inventory menu when player selects an Item

Hi, I have an inventory menu that shows when you click on a button inside the game. The inventory is a menu that appears in the middle of the screen.

What I want is for this menu to close automatically when an item is selected. How can I do that?

Thanks!

Comments

  • There are a couple of ways to do it:

    The first is to override the default left-click behaviour of an Item to both select the item and close the Menu.

    Create an ActionList Asset that and give it the "Inventory: Select" and "Menu: Change state" Actions.  Use the first to manually select the item you want, and then the second to Turn Off the Inventory Menu (assuming it's still named "Inventory").  Then assign that asset as the item's "Use" interaction in the "Standard interactions" field in the Inventory Manager.

    This method can all be done within AC, though has to be done for each inventory item you can carry.  The second method is much more simple, but requires custom scripting.  If you simply want the Inventory menu to be off whenever an item is selected, you can use the following code:

    if (AC.KickStarter.runtimeInventory.selectedItem != null)
    {
      AC.PlayerMenus.GetMenuWithName ("Inventory").TurnOff ();
    }

    Placing that in an Update function of a custom script and placed on an empty GameObject will cause that code to run every frame - and so turn off the Inventory Menu automatically.
  • Going the ActionList route mentioned above, is there a way to disable the need to de-select the currently selected item before you can select a new one in the inventory?

    I tried putting a Inventory Select > Deselect Active in front of the two actions mentioned above but it doesn't seem to make a difference.
  • Is there any event for when an item gets selected? I can't recall, but if not, it would be pretty cool if there was one (it would help avoid unnecessary use of the Update() function).
  • @netto: If an inventory item is already selected upon clicking another item, it's assumed that you're attempting to combine the two, so the relevent "Combine" interaction is run - so the "Use" interaction described above isn't run.  You could either assign that same Interaction as your item's "Unhandled combine" Interaction, or use the OnInventoryCombine event so script something automated.

    (Custom events are described further in this tutorial)

    @Alverik: Yes, OnInventorySelect is called, with the Inventory Item assigned as an InvItem parameter.  In hindsight I should have suggested that instead.
  • Hmm, that still doesn't seem to work.

    If item A and Item B both have above ActionList assigned as both the Use interaction and the unhandled combine interaction what will happen is:

    1) Be uneqipped, and access inventory and equip item A, inventory closes down and item A is equipped as expected.
    2) Access inventory again, and go to item B and choose to equip it, the inventory closes (as desired), but item A is still the equipeed item.

    Any ideas/thoughts?

  • If you're using the same ActionList for both A and B, and that ActionList manually selects Item A, then clicking either item would cause item A to be selected.  You need to create separate ActionLists for each item.
  • edited December 2016

    Sorry, I'm not being clear I think - they are using separate action lists.


    Item A, has an actionlist called ItemAUse attached to the use interaction of item A, then I've created a separate actionlist that's identical to ItemAUse, called unhandled_ItemA_combine or some such, and assigned it to the unhandled interaction for item A.

    In this ActionList ItemA is the inventory item that's being affected in the "Inventory: Select".

    For Item B, I have the same setup as above, but in the ActionList item B is the one that's affected in the "Inventory: Select" for the action list.

    I can get some screenshots together if needed?

  • No, I see the problem.  It's that the "Unhandled combine" is used on the selected item, not the item you're using it on.

    You'll therefore have to use a custom Action in your "Unhandled combine" ActionList that simply selects the inventory item that the cursor is hovering over at the time.

    Try this: http://paste.ofcode.org/GqedULujAvRANFLY5AiS7r

    Place it in a script named ActionSelectHoverItem and follow the steps in this tutorial to install it.
  • Brilliant Chris that works like a charm!

    Again, I can't express how grateful I am to the support you're providing. It's really above and beyond most times.
  • edited August 2018
    I know this an old topic, but I wanted to add a "work around" to custom scripting that could be useful to some others encountering this problem.

    Create another menu called "selected item". Set appear type to while inventory selected and create an action list to turn off the inventory menu when the selected item menu is on.
  • Thank you Stranga

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.