When I make an Array on EventPlay the order is good at Play, but the order will reverse after 2nd Play

I noticed that if I make a blueprint that builds an Array of actors of the same Class on EventPlay it works great on the 1st EventPlay, but the Array order index is reversed if you press Escape and press Play again, it also doesn’t matter if the Array is created by promotion of Class actors Array value or if they’re added to the Array by For Loop. Same thing happens with Assign, except for the reverse order it will count double digits on order of the first digit.

If you save everything and close Unreal completely, restart unreal and load the saved project, Array order is normal again at 1st EventPlay.

I assume this has something to do with reading the Object names in a particular order.

I hope my symptom description is clear enough. I would also be very open to workarounds that would make me able to control the index order of Actor Arrays without having to restart Unreal.

Hi B,

I wasn’t able to reproduce this behavior in 4.12.5 and I have some additional questions.

How exactly are you creating the bp setup (a screenshots or a small test project would be appreciated)? In the actor class itself. another bp actor, or in the Level Blueprint?

Hi TJ,

Please know I’ve altered the problem description after more testing, and I have the following information/material for testing:

I’ve created a new project and recreated the described situation in its most simple way, and was able to reproduce the problem. At first Eventplay the Array index order is ok, when press play again the order is reversed. Then it will stay quirky either giving reverse values or scrambled values… :S

DL link of the project:
https://www.wetransfer.com/downloads/0cadb84030121e043faead17da57b07520160709104657/7e1171d9428166ffce4544e04c53c42220160709104657/19e921

I’m not working in the Level Blueprint, but I have 3 Blueprint Actor Classes. One Class that has 13 Actors present in the level. One that I’m using as ‘Master’ Having the collisionbox and the nodes to do the Arrays and key input. And one I’ll be spawning from the master blueprint Class. Only the master blueprint class has nodes:

When the problem happens and press Play again sometimes the values also get scrambled at EventPlay:

97806-scrambledvaluesateventplay.png

The problem disappears for the 1st event play after UE restart and then returns after the first play. The biggest problem is that it’s not stable, and the index would not be useful for anything else but keeping a list of names for which the index integer values may vary on each EventPlay.

Note: Even if I would disconnect the ForLoop to spawn the Sphere Actor Class Actors so it doesn’t populate the second Array the problem remains.

Update: Managed to Sort the Actor Index by Z coordinate. It works as a work-around, and actually would fit my current design better. But it is strange that an array index order is different between EventPlays.

Update: Found the same irregular behavior is happening with the Array of spawned actors… I just didn’t notice it as I wasn’t looking at the ObjectNames…

Hi B,

Sorry for the delay, but I’m glad you found a workaround.

So the GetAllActorsOfClass node basically just randomly gets all of the actors, which is why you are seeing varying results. We actually have a feature request in (UE-28730) to implement a SortArray node into blueprints.

Currently you would need to either sort the array manually or use a user created extended blueprint library with this functionality. Here is some more info on that.

As for an array of spawned actors, could you please elaborate on that a bit. Is this a preset array that is then spawned in or are they added to an array at spawn?

I’m not sure if the DL link is still active but it should provide the exact case in the BP. Just instead of printing the spawned actor object ID’s, print the spawned object names to visualize it at play. I’m adding the BP actors to the array as they are spawned.

A SortArray Node sounds like a great option, it would open up a lot of possibilities for sure. :slight_smile:

Another side-note: If I populate another Array from a sorted array for example the vector values of the actors in the Array (with ForEachLoop Insert) it seems to copy the ID mapping normally, it’s been consistent so far.

I set this up two ways:

One using the blueprint in your project. Doing it this way, it is just running into the issue I described above which needs a sort node to fix.

The other is, as I spawned the objects in, I add them to the array. When I do it this way, they are always sorted correctly in the array. Since you found a workaround that works for your project, it doesn’t really matter. But this method works quite well.

That’s what I thought initially, as the array ID order of the spawned actors itself is in order each Event Play (the 0-12 in the screenshots are spawned actor ID’s, the actors are added to Array at spawn), but I found the spawned actor ObjectNames to be linked to the wrong ID occasionally on various Event Plays very similar to the behavior of the non-spawned actor Array.

Here is what I’m doing to get the results I mentioned. Could you explain what changes to make to see the ObjectNames linked to the wrong IDs?

Resurrecting this thread because it’s the same problem with me, and it even goes full random if you put the actors above a static mesh.

TJ, does Epic have an ETA for the Array Sort, or some kind of temporary solution?