How to get all actors of subclass from an array of parent class

Hello,
I have a parent actor blueprint class lets call it parent_class. I also have four different children class lets say parent_class_A to D. If I have an array filled with all actors of base class (so it consists of actors parent_class_A to D) how would I go about getting for example all actors of parent_class_C from it so that blueprint editor knows its not the parent class but the child class? I can check for the class of each actor in the parent_class array but I won’t be able to set them as reference to parent_class_C as they are still references to parent_class.

Hi, could you explain what you want to use this for?

Without more information, I would say loop through the array and cast it to the class you want to have (e. g. parent_class_C) and if the cast succeeds add them to an array of that class. But that is not a solution I would generally use, so it might be better if you try another approach (than having an array of parent class and get actors of subclass from that) to solving your problem.

Thank you for your time and the link, will have a look at it.

Oh right you can cast of course. I just thought it would be more efficient to have to execute get all actors of class only once for the parent class and than access this one array to get children instead of getting actors of each specific child_class and adding them to four specific arrays or would this be better? Thank you for your reply in any case.

If you use GetAllActorsOfClass, then UE uses hash tables under the hood (but if you use something like GetAllActorsWithTag or GetAllActorsWithInterface then it will iterate through all actors that you have in your level, will use GetAllActorsOfClass with AActor as class). If you use GetAllActorsOfClass parent_class, then it will first add that class and all its subclasses into an array and then loop through that array and access the objects associated with that class from the hashtable and iterates through them all and adds them to the output array.

So my guess would be that using GetAllActorsOfClass for each child class and just directly use that array will be faster than using GetAllActorsOfClass for the parent class and then looping through them all in blueprints.

And I also found this performance comparison interesting Get all actors of class vs Get all actors with tag - Blueprint Visual Scripting - Unreal Engine Forums