Set Array Element returning Invalid


I am using version 4.15.1.

I’ve been following along with the “Drag & Drop with UMG” series on YouTube and have encountered a problem that the videos don’t seem to encounter or address.

Basically I have an Array (called Inventory Items) with Object as its type, and 20 items in it. I run a For Each Loop to find an ‘empty’ index in the array, and to skip past any index that is not blank.


When an object (I’m adding an actor blueprint to the array) is set to an index in the array the following screenshot shows that the array is updated and that index is no longer ‘empty’. The problem I have is if I run the For Each Loop again to find the next ‘empty’ index, it still returns the first index as being invalid (or ‘empty’) despite the Watch Value showing that there is an object there.



Any further attempts to add an object to the array will simply replace the first index in the array, as the For Each Loop always determines the first index to be invalid.

Am I missing something? Or is the Array not working as it should?

Do you at any point destroy the picked object?

Try making sure it’s not a flaw in your logic.

Search in your code for clear array node occurrences. Maybe even external BP’s would be doing this job, so check everything that uses your class.

And as Everynone mentioned: Is your reference stored being destroyed at some point? If yes, you should guarantee that the object would be valid in the moment of the check.

One thing to point out in your logic is when your array is full and have no available space. In this case, you will execute the Completed node, from the ForEachLoopWithBreak. If your variable “EmptySlot” is set to zero as default value, you would return the empty slot value of zero (first index of your array), and your array would be overwritten in the wrong slot accidentally.

Consider setting the default of your EmptySlot variable in a symbolic value, such as “-1”, and after calling this method, check the returned value: if >=0, then proceed; else, the array is full.

That was it! A delete actor node sneaked in somewhere along the lines that wasn’t meant to be there. I hid the actor and disabled collision (following the tutorials) but added a delete actor at the end, silly me haha.

Thank you very much!