Forum rules - please read before posting.

Inventory Box / Container Issue

I am seeing an issue using Direct Control when transferring an item from a container to the player's inventory;

When the item is placed in the inventory from a container, the item is then automatically selected. This can be pretty annoying for the player, as they often want to take another item from the container but don't realise they already have an inventory item selected, so they then have to move back over to the inventory box again to return the item.

The inventory uses the default AC menu, not Unity UI, so we can rule out any kind of conflict there.

I am using AC 1.74.2 but don't remember seeing this issue before now.

Comments

  • What version were you previously using?

    InventoryBox elements that are set to display a Container have a Click behaviour property, which controls what happens when an item in the Container is clicked.

    By default, this is set to Move To Inventory And Select. Setting this to Move To Inventory should prevent the additional selection.

  • Before this I think I was just on 1.74 maybe? It's actually a while since I updated to 1.74.2, but I didn't notice this until now. It might have already been like that before, but I am deeper into testing now so I've noticed it.

    The Inventory Box type of the "ContainerItems" is set to Select Item Only, this is because I want the player to move the item manually to the inventory (I'm making a Resident Evil-style simple limited inventory grid).

    So selecting the item works fine, but when the player actually puts the item in the inventory, it then gets selected, which is undesired.

  • If you're requiring the item to be selected in order to transfer it from the Container to the Inventory, is it then not a case of the item remaining selected after placement? I think I need some clarification on the behaviour.

    There's a lot of settings involved that will make the behaviour unique to your project. Lets see your Settings Manager to begin with, and also the stacktrace involved when the item is selected at the wrong time.

    To do that, open up RuntimeInventory.cs and place the following at the top of its SelectItem function (around line 185):

    if (!InvInstance.IsValid (invInstance)) Debug.Log ("Select " + invInstance.InvItem.label + ", Previous: " + InvInstance.IsValid (selectedInstance) + ", Matching: " + selectedInstance == invInstance);
    

    At the point that the item becomes selected at the wrong moment, the Console should display a new message related to it. Copy/paste the contents in full here.

  • I think that's exactly it Chris, the item remains selected after it has been placed.

    I found the SelectItem function, sorry but not sure where to put this line of code? I tried line 185 (and others) but got this error:

    Assets\AdventureCreator\Scripts\Inventory\RuntimeInventory.cs(185,62): error CS0019: Operator '==' cannot be applied to operands of type 'string' and 'InvInstance'

    Most likely I've put it in the wrong place :/

    Could you say which part of the Settings Manager you need to see? Is it the interface & inventory settings, or the Menu Manager e.g container, player inventory etc.

    BTW I don't think this is a bug, but rather just slightly odd / unexpected behaviour in regards to functionality. I've never played a game with an inventory/container system that keeps an item selected after it has been placed in inventory, basically.

  • I tried line 185 (and others) but got this error

    I mis-typed. Try this:

    if (!InvInstance.IsValid (invInstance)) Debug.Log ("Select " + invInstance.InvItem.label + ", Previous: " + InvInstance.IsValid (selectedInstance) + ", Matching: " + (selectedInstance == invInstance));
    

    Could you say which part of the Settings Manager you need to see?

    Best to see the whole thing.

  • Okay, no errors with that debug line, though nothing is actually printed in the console?

    Anyway, I made a video of the problem to make it clear:

    I take an item from the container and put it in the inventory.
    I then close the container. You will see that the inventory item is still selected.
    video

    So basically, inventory items should not remain selected after removing from a container and being placed in the inventory.

    As requested, I will follow this up with images of my Settings Manager.

  • If need be, you can force the de-selection by way of the Inventory: Select Action at the same time that you close the Container.

    Can you also share shots of the Menu / Elements involved? And are you involving any custom scripts that may affect things?

    Another Debug.Log statement: this time at the top of the InvCollection script's Insert function, around line 330:

    Debug.Log ("Insert " + addInstance.InvItem.label + " to slot " + index);
    

    Assuming this shows at the time, what is the message in full?

  • edited February 2022

    Okay, sorry for the delay on this, but here we are. Also no relevant custom scripts are being used at all:

    Settings

    Okay here is the debug. I have an inventory item called "Motion Sensor" that I collect from the container. I put it back, then retrieve it again:

    Insert Motion Sensor to slot 0
    UnityEngine.Debug:Log(Object)
    AC.InvCollection:Insert(InvInstance, Int32, OccupiedSlotBehaviour) (at Assets/AdventureCreator/Scripts/Inventory/InvCollection.cs:331)
    AC.MenuInventoryBox:HandleDefaultClick(MouseState, Int32) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:1189)
    AC.RuntimeInventory:ProcessInventoryBoxClick(Menu, MenuInventoryBox, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Inventory/RuntimeInventory.cs:1020)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2322)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2329)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1918)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2037)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2025)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:204)

    Insert Motion Sensor to slot 5
    UnityEngine.Debug:Log(Object)
    AC.InvCollection:Insert(InvInstance, Int32, OccupiedSlotBehaviour) (at Assets/AdventureCreator/Scripts/Inventory/InvCollection.cs:331)
    AC.MenuInventoryBox:ClickContainer(MouseState, Int32) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2236)
    AC.RuntimeInventory:ProcessInventoryBoxClick(Menu, MenuInventoryBox, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Inventory/RuntimeInventory.cs:1027)
    AC.MenuInventoryBox:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuInventoryBox.cs:2322)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2329)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1918)
    AC.PlayerMenus:CheckForInput(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2037)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2025)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:204)

  • Your ContainerItems element's Click behaviour is set to Select Only. Set this to Move To Inventory to have it transfer only.

  • edited February 2022

    Yes, if you refer to my second post, you'll see that I wanted the player to manually select items and move them from a container to the inventory (then the item be deselected).

    However, I've since changed my mind on this and I'm just going to roll with the Move To Inventory option. Nothing of note is really lost, in fact it's less of a pain so the compromise is worth it. To ensure the player never exceeds the limited inventory, I just have an action list that runs on the Close button to prevent the container menu being closed if the player is carrying more than the supposed limit.

    Thanks for checking it out again though.

  • You can force the de-selection of any item by placing an Inventory: Select Action inside your Container menu's "ActionList when turn off" asset, and have that Action deselect the active item.

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.