Hi, I’m trying to make an inventory system and for some reason when I walk over an item it’s not getting added to the inventory, I’ve ran the game and it all flows up to the ‘Add’ node. It’s meant to be searching the inventory of the player that walks over it, if it doesn’t find an entry in the inventory with that name it adds the item to the inventory as a new array entry, but for some reason it’s not getting added.
The array does not increase in size or the newly added struct contains unexpected data?
Or perhaps you were expecting the Third Person Character’s *Inventory *array to be modified - that’s not going to happen since you’re working on a copy of the array here.
The array doesn’t increase in size, by default I have nothing in the inventory, but this is supposed to add the item to the inventory when stepped on and instead it does nothing, returns no errors or anything
Are we talking about Player Inventory Reference here - you called it a reference but it’s not, it’s a copy. You keep adding elements to the copy, and the changes do not propagate back to the TPP.
Ah right, I see where I wen’t wrong, I’ve fixed it now, thank you!
Structs are nasty like that. You need to insert them back in the original array as even *For Loop *creates a copy of the iterated struct already. The Set Members in Struct node helps a little but working with structs arrays is full of gotchas.
Good luck with the rest!
Out of curiosity… instead of setting a boolean on branch(true) why not simply add to the item to the target → inventory, then break. Completed doesn’t have to execute anything.
Probably because there are more code and logic after adding item to the inventory…and maybe he need to know if the item is added or not. I would almost always break the loop and connect with “completed”, specially in functions with return node. However, when you break the loop, Completed node is executed.