Why isn't there a check for Empty Array Index?

Hi,

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?

Thank you,

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:

http://i.imgur.com/OwYlFWt.png

Yeah, that’s the bothersome part. That works for Actors. For a float you could go with 0. With a bool the opposite of the default, etc.

In my case I’m using a struct, so I had to create a “dummy” default value.

Thanks,

“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.

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 .

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”

This is great. Thanks both of you.

I know this is an old question but there is isValid? build-in function checking if eg. an element from an array of actors is an actor - it does the job.

In BP you should use the IsValid node rather than checking if a UObject == nullptr. Much easier to read too in my opinion

Both ways work well

350501-is-empty-array.png