Forum rules - please read before posting.

Item not disappearing in Inventory menu

budbud
edited June 2022 in Technical Q&A

I am using a custom script to handle the Inventory Interaction of a hotspot
I use this code to remove the item from inventory:
KickStarter.runtimeInventory.Remove(inventoryID);
PlayerMenus.ResetInventoryBoxes();

The item is removed from the inventory, BUT is still visible in the inventory menu.
On Editor stop and play, then it's gone, obviously because its in fact not in inventory any more.

How to fix this ?

I also have an additional question:
I am making a custom script to pickup an item. I use custom script from interaction-use in hotspot to trigger the pickup.
What I want to do, is to have a list of all inventory items in inspector to choose which inventory item to add.
Any suggestions ?

Comments

  • edited June 2022

    The item is removed from the inventory, BUT is still visible in the inventory menu.

    How are you determining this difference?

    Rather than the two lines of code you're using, try calling the InvCollection's Delete function instead:

    KickStarter.runtimeInventory.PlayerInvCollection.DeleteAllOfType (inventoryID);
    

    What I want to do, is to have a list of all inventory items in inspector to choose which inventory item to add.

    You can create an array of item labels by iterating through each item in the Manager. Since item IDs aren't necessarily the same order, however, you'll need to convert between a temporary "index" variable:

    int ItemSelector (int selectedItemID)
    {
        System.Collections.Generic.List<string> labelList = new System.Collections.Generic.List<string>();
    
        int selectedItemIndex;
    
        foreach (InvItem _item in KickStarter.inventoryManager.items)
        {
            labelList.Add (_item.label);
    
            if (_item.id == selectedItemID)
            {
                selectedItemIndex = KickStarter.inventoryManager.items.IndexOf (_item);
            }
        }
    
        selectedItemIndex = UnityEditor.EditorGUILayout.Popup ("Inventory item:", selectedItemIndex, labelList.ToArray());
        selectedItemID = KickStarter.inventoryManager.items[selectedItemIndex].id;
        return selectedItemID;
    }
    
  • Unfortunately, the KickStarter.runtimeInventory.PlayerInvCollection.DeleteAllOfType (inventoryID); did not work, its in fact exactly the same happening as when using the KickStarter.runtimeInventory.Remove(inventoryID);

    I get the inventory item id passed from the hotspot inventory, custom script setup

    I uploaded a video to show what's going on:

    Comments to the video:
    The leftmost door accepts the inventory item
    When using the inventory item on this door, the item disappears from the inventory menu (not the inventory itself), as you see in the video as no tag is showing when cursor is over item after the item is used, and dragging the item just moves the camera.
    After stopping the Editor and playing again, it's back to normal, with item in the inventory menu.

    Hope this gives an idea of what's happening, and how to fix this.

    PS: Your solution for the second question worked very well, thanks a lot

  • Thanks for the video. It's a strange issue to be sure - not one I've come across before.

    The code should work, and it looks like the item is being removed. It looks like a rendering issue.

    We'll need to determine if this is Unity UI related. If you switch your Menu's Source to Adventure Creator, do you still get the behaviour?

    Separately, try also switching the Appear type back to Mouse Over, so that the Menu turns off and on again when testing. Does the item remain when the Menu turns back on?

  • budbud
    edited June 2022

    When switching Menu's Source to Adventure Creator, it works.
    It also works when setting the Appear Type to Mouse Over.

  • Just to be clear on the Appear Type test, that was a separate test (Unity UI).

  • edited June 2022

    Sorry for not asking this earlier, but what are your AC and Unity versions?

    Can you also share screenshots of your Settings Manager's "Inventory settings" panel, as well as the properties of both the Inventory menu, and its InventoryBox element?

    It may be down to some change made from the default settings - I've tried recreating it with the default UI menus but haven't had luck so far.

    Does this issue occur if you run the code to remove the item without selecting it first, and does it occur if you switch over to the Default_MenuManager asset, and set the default Inventory menu's Source to Unity Ui Prefab, and Appear type to Manual? (I'm assuming this is what yours is set to)

  • I am using latest AC version 1.75.3 and Unity version 2020.3.30f1

    I have set the Inventory Menu's source to "Unity Ui Prefab" and Appear type to "During Gameplay"

    Removing inventory item w/o interacting with the menu did not help, same as before.

    See attached screenshots:
    https://drive.google.com/file/d/1qZH116bEBVUn1SlrcB5ISHvrnZ2sS8uP/view?usp=sharing

  • To be clear: this issue also occurs if you use the Inventory: Add or remove Action to remove the item instead?

    Can you PM me your Manager asset files, along with the Inventory UI prefab assigned as the Linked Canvas Prefab? If your custom code is necessary to recreate the issue, I'll need that as well.

  • Using inventory Add or remove in an action list works.

    Today I had another issue passing parameter to ActionList that did not work, and this should work.
    So I did a clean project and started from scratch.

    Now everything works as it should.
    There must be something happened with some files or something strange.

    Anyway, I think I will just redo everything, and hopefully things will work as intended. If for some reason this issue comes back, I will let you know.

    Thanks for the help.

  • PS: If you still want to investigate this issue, then let me know, and I can send you the files you requested.

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.