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"

Emty object array returns length 1

Hey all,

when i try to get the length of an (empty) object array it always returns 1. What is up with that? Is this behavior intended?

Best regards,


Product Version: UE 4.20
more ▼

asked Aug 26 '18 at 04:43 PM in Bug Reports

avatar image

3 1 3

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

2 answers: sort voted first

No, not intended. Create a new variable, make it into an array, get length, you'll get 0.

Show us how you handle the array you find problematic.

more ▼

answered Aug 26 '18 at 06:10 PM

avatar image

15.2k 77 25 62

avatar image Maffinius Aug 26 '18 at 06:48 PM

alt text

alt text

The array is not used so far and empty. String-output: Arraylength: 1

Thanks in advance :)

ue4screens.png (157.6 kB)
ue4screens2.png (102.9 kB)
avatar image Everynone Aug 26 '18 at 06:57 PM

Looks good. This would only print 1 if you dynamically spawned and added a worker. You sure nothing like that happens somewhere on a forgotten Begin Play? A testing leftover of sorts?

As an easy debug, open a New Task Villager blueprint and Prrint String something on its Begin Play event. Does it spawn?

avatar image Maffinius Aug 26 '18 at 07:19 PM

alt text

alt text

I also print the arrays content right after printing out the length. Nothing is printed out and the length is still 1 :( I also double checked all begin play's and event graph's (even though i'm 100% sure that i nowhere create or add villagers :/)

I also print a string in the begin play like u suggested but no villager is spawned somewhere

ue4screens3.png (75.6 kB)
ue4screens5.png (121.8 kB)
avatar image Everynone Aug 26 '18 at 07:26 PM

Weird, as test, can you call Clear on the array and then print it?

avatar image Maffinius Aug 26 '18 at 07:45 PM

Ok when i call clear directly before calling the printArray function its has no impact. If i call clear in the printArray function (directly before getting the length) i get length = 0. My suggestion was that i maybe do something wrong in eventTick but there is nothing that has anything to do with the villagers.

EDIT: i changed the arraytype from Unit_BP array to Object array and now i can call clear the array before calling the function to get length = 0. but the main bug is still happening

avatar image Everynone Aug 26 '18 at 10:42 PM

One more thing you could try is to Print it in Tick and observe how early it becomes 1 in the log.

Also, do you know why you have World Context Object on your nodes? Haven't seen this in years...

This is not a pure blueprint project, right?

avatar image Tuerer Aug 27 '18 at 10:51 AM

This happens sometimes if you drag an actor variable and select the print string node directly, without ToString() function. it creates this input pin. And it may sometimes stay there even if disconnected.

avatar image Everynone Aug 27 '18 at 03:41 PM

@ Tuerer: Thanks! It seems like it does not do much anyway.

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

OK i looked up my right mouse event again since the length was set to 1 every time i pressed it. It appears that i made a new array ("make array") with no content at the end. I use "clear" now and it works perfectly fine.

Thanks for youre patencience and help :D

PS: Is it intended to have length 1 when i make a new array with no content?

more ▼

answered Aug 27 '18 at 10:15 AM

avatar image

3 1 3

avatar image Everynone Aug 27 '18 at 10:16 AM

No, definitely no. Can you show a screenshot of how you do it? Make Array has a very specific use, perhaps it is not being used right.

avatar image Maffinius Aug 27 '18 at 12:51 PM

alt text

I used "make array" like this. EDIT: Just saw the "remove array element pin" option ... this works aswell ^^

ue4screens6.png (140.8 kB)
avatar image Everynone Aug 27 '18 at 01:15 PM

There we go. Your array now has 1 element at index zero. You do not need this at all and it's actually quite dangerous to use it like this for actors as you create a null pointer.

By simply having this variable, you already have an empty array - no need to make array. Try it.

(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