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"

For Loop => Remove Item (or index) from array


I try to spawn actors on a grid.

  • Each location is specified in an array and is unique.

  • In my project I don't want all the locations to be filled so the last index will not be the length of array,

  • I want unique actor by location

  • I put it in player controller because I will use it in a Networked game

  • Here my grid is a simple line for demo of my bug.

So in attachment you can see my blueprint and the result in game, this is not a full line, some actors are missing. I was expected that the line be filled up because the Last Index is equal to the array length.

In the loop the item is not removed. So 2 or more actors use the same location. What have I done wrong? Is it a bug or an expected behavior?

Thanks for your help.

PS: In my game I use it as a function to execute it with different class of actor in order to partially fill my grid with differents actors. I don't wand my grid to be fully filled. But only one actor by loction. So another method can help too.

Product Version: UE 4.18
capture.jpg (266.1 kB)
capture2.jpg (24.7 kB)
more ▼

asked Jan 29 '18 at 09:34 AM in Blueprint Scripting

avatar image

125 7 10 13

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

1 answer: sort voted first

The issue here revolves around the way you use the random node. It is used twice, 1st time to Get and 2nd time to Remove an array element. You'd expect it to produce the same value twice but that's not the case. It is working as intended, though.

So you Get one random index and then Remove another random index - different from the 1st.

In order to work around it, store the result of the random generation in a variable and use the value to access the array. This should be the first step to take; if there are more issues, let us know.

more ▼

answered Jan 29 '18 at 10:09 AM

avatar image

15.2k 77 25 62

avatar image Metathesus Jan 29 '18 at 04:26 PM

Of course! Why I haven't seen it?!! Thanks a lot!!

(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