Find actors then sort

Hello,

Is there a way to find all actors of class in scene, then sort them either by their name or by a variable name inside my actor?

Hey,

One way you can do it is by creating a sort function that goes through the array and swap them to the correct position. In my included image I added an integer variable to my actor called “sort by me” then I sorted so the bigger value would be first in the array. The same functions can be reused, and you can just change the sort function how you want the sorting to work.

First, we get all the actors of our class, then we send them into the sort actor array to get a sorted array of them.

The sort actor array goes through all elements and checks them against each other to see wish one should be first, swapping out as needed.

The checking happens in the actor sort function to see wish if A should be before B, this function can be changed to however you want to sort algorithm to work.

Just add the sort functions to where you need it, or create a blueprint function library if you will be using it in more then one place.

Hope it helps!

2 Likes

This worked perfectly! Thanks from the bottom of my heart. Never had an answer this well explained.

Really helpful to me also, thanks!

What would be a way to reverse the sorting order?
Like descending instead of ascending.

Thanks!

Thanks a lot! This is exactly what I need and it works. I racked my brains for a long time trying to do this myself. I’m very lucky to have found your example.