x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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,

Product Version: UE 4.10
Tags:
more ▼

asked Feb 20 '16 at 01:19 PM in Blueprint Scripting

avatar image

Arcade
43 7 12 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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

more ▼

answered Feb 20 '16 at 04:58 PM

avatar image

ScottSpadea
9.6k 320 205 449

avatar image Arcade Feb 20 '16 at 09:14 PM

This is great. Thanks both of you.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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:

alt text

more ▼

answered Feb 20 '16 at 02:10 PM

avatar image

JoshieZombie
271 22 20 26

avatar image Arcade Feb 20 '16 at 03:24 PM

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,

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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"

more ▼

answered Feb 20 '16 at 06:03 PM

avatar image

Shadowriver
36.7k 932 169 1111

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question