Download

Could Someone Explain Me Why GET ALL ACTORS OF CLASS Acts So Strangely?

I have some BPs that have just a mesh added in their viewport with no collision, no physics, nothing basically placed in te level.
I get all actors of class to add a spline based on these BPs locations, then divide it to get equally spaced coordinates along spline at points which coordinates finally are used as nav points.
These BPs are called something_01, something_02, something_03 and so on incrementally.
When I get all actors of class the sequence is all messed up, it basically shuffles the array with no apparent order.

To “fix” this I used to compile the nav point BP and then at execution of the level the were lined up correctly, this has worked until I had opened the level containing the BPs path.
Now that I’m loading this level from another one there’s no way to get the nav points sorted sequentially.
I have even set up some logic to sort them, this works until this logic is executed in that same level, when I load it from another one everything get messed up.
Is it normal? Is there a way to get actors in the same order as they’ve been placed in the level?

I’m not sure. GetAllActorsOfClass should also be avoided any time. It is pretty expensive and most of the time, people use it because they don’t want to think about a proper way to get these actors.
A good way would be letting the Actors register themselves in a Class that is easy reachable. For example an Array in your GameState class.
Then on BeginPlay, the Actors could get the GameState and add themselves to the Array. With this you wouldn’t need the GetAllActorsOfClass.
And you could also run a sorting algorithm, either each time a new actor gets added or at specific other timing points that you might choose.

Ok I understand.
I chose Get All Actors Of CLass because at Begin Play I could get the path nodes independently from the track.
I mean: if there where 12 tracks I had to manually create 12 different arrays and then create the logic to tie one of them to the track chosen by the player, GetAllActorOfClass seemed a good solution.

So I could make the nav point itself add its position to the array in the Gamestate and then sort them, I think this is a good way to make it.
It could be used a delay of one/two seconds to sort the array to be sure that all the nav points have been added to the array.
Many thanks again eXi.