Why isn't there a check for Empty Array Index?
I've seen a bunch of questions on how to see if a particular Index in an Array is empty, which is just what I want to do as well. What I've seen is that there's no "Is it empty?"-check at all, and you always have to do some roundabout weird way that changes depending on what type of Array it is.
Is there a clever engineering reason for why there isn't just a "Is this Index empty?"-check in the Engine?
asked Feb 20 '16 at 01:19 PM in Blueprint Scripting
"Is there a clever engineering reason for why there isn't just a "Is this Index empty?"-check in the Engine?"
an index cant be empty. an index is just a memory address relative to another memory address. every memory address has a value, whether that value is useful or not. keeping track of which indicies have been changed from their default values can be a cheap way to know if the value is still useful, but if you want to use the default value as a valid value, you would need extra memory to store its "emptiness" as a boolean.
the overhead of adding an extra boolean property to every single datatype would be enormous. it would add an extra byte to every array entry, so if you were sending an array of bytes across a network, this would double the amount of data you need to send. its much cheaper to decide that 255 represents an empty byte.
answered Feb 20 '16 at 04:58 PM
Sure would be nice if there was a single node for this, yeah.
Now this may not be 100% the correct way to do it, but I usually do something like this anyhow:
answered Feb 20 '16 at 02:10 PM
To add what said ScottSpadea
Array implementation in UE4 universal and can either data or pointer (memoery address) to data and only pointers can have empty (aka NULL/nullptr) and on blueprints only Objects are used with pointers, so implementing one function for just one type of array would have been wierd.... but they could make a node like that imo.
Generally you should remove item from all arrays it is in when it gets destroyed, this way you don't need to check "if it is empty"
answered Feb 20 '16 at 06:03 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here