In my inventory system, I’m dynamically creating items by using “Create Widget” function and then placing them in my grid using “Add child”.
My layout:
Right side: inventory grid
Left side: Current equipment
You can equip every item by clicking action button (not visible here). I found that if you want to move existing widget (in my case, item in grid) to another widget (eg. helmet tile), you can call AddChild function.
Problem:
When I pick up an item, it shows in first tile as expected. I can also move my widget to equipment.
What I can not understand is where I use item (it’s moved to EQ) and first tile in grid is empty again, I pick up another item and… it doesn’t show up. I double checked everything:
Item widget is properly created, not null.
There is no child in first or any other tile
Question:
Why when I want to add a child widget to border after removing previous child, it is invisible (I also cannot interact with it)?
Give my answer a go first, and if that doesn’t work then, just for debugging purposes, try to do this without collecting the items in game.
What I mean by this is in IG, add a 1 second delay to the begin node to spawn in an item, then another 1 second delay to remove from parent, then yet another second before adding a new one.
If that works, then, instead of removing from parent, equip it into EQ, then carry on with adding the new item into IG.
Also try adding a different item. If its a sword the first pick up, try picking up a shield the second time.
Based on what happens we can take further actions.
Try copying the original item into a variable name something like copiedItem , then removing the original from parent.
After that, add the new copiedItem into EQ.
What might be happening is there is a reference being left behind in the grid when it is moved.