Remove Index not deleting Array element

So I have a key that’s in the inventory of a player character, and the chest that it goes to. When the player attempts to unlock the chest, the chest will check the player’s inventory, and if they have the corresponding key, the key should be removed from the player’s inventory, and the chest should open and give them the treasure.

From what I can tell, the key does get removed from the index, but the index doesn’t get removed from the array. It just shows up as “None” when I look at the player’s inventory, and the indexes don’t shift up. I tried looking around at other questions to see if I could find the answer, but to no success. If anyone knows what might be happening here and how to fix it, it would be a big help. Thanks in advance!

You’re removing the Index from a copy of the array not a reference. You’ll have set the array again in the struct after removing the Index.

1 Like

I figured out the problem. My inventory in this screenshot was actually a variable I was assigning in a parent, and not directly the inventory attached to the parent. I swapped out that variable for the player reference itself, then grabbed the inventory there, and it looks to be fixed!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.