How to get all children with parent class

Hello everyone.

Can anyone tell me if there is a way to get all children from parent class. For example , i have a FatherWeapon class and i want to get all children of that class for example: Assault, Shotgun, Pistol etc… Can i get all those children in some Array or anything like that? I would mainly like to get a Children Class!

There is a Node called Get All Child Actors but how does it work? Do i have to Spawn FatherWeapon class and then connect it’s reference to Get All Child Actors and get array? Because that gives me nothing.

Also there is Get All Actors Of Class but in order to get them, they have to be into Level and i don’t want them to be in level i want to spawn them when i need them.

Anyone already solved this?

Thanks in advanced!

make array of your parent class, but you must “Class” rather than “Reference”
then you must fill this array

and you can get any children class by index

Thank you very much, but is there some more automatic way? I want to make it more dynamic so when i add some child later it’s added automatically to the array.

TObjectIterator in C++, I took this snippet from the AnserHub thread I linked at the bottom. It does appear you need to actively do a search, assuming you aren’t trying to add new classes at runtime, it can do it once at the initialization of the class that needs the list and add them at that time.



  for(TObjectIterator<UClass> It; It; ++It)
  {
      if(It->IsChildOf(BaseClass::StaticClass()) && !It->HasAnyClassFlags(CLASS_Abstract))
      {
          Subclasses.Add(*It);
      }
  }


https://answers.unrealengine.com/questions/443503/c-get-all-subclasses-of-a-given-class-without-incl.html

Thank you so much! I will try this! And if anyone also has any idea, please feel free to post!

On begin play add “self” to an array you’ve created in the Parent Class…for example in my game all enemies that spawn as Alice goes about her level Add themselves to an Enemies Alive Array so that I can count down to Zero when Alice kills them all (they remove themselves from the array when their life hits zero) and is no longer in Combat…

Right i trying this. But in Blueprint

I got a base_Player, I want to get all children of the players. Then make reference to that one.
So I can use there variables and stuff in Player controller.
Class array of Base_Player - for each loop etc… what next?

72d4385a139ba5c8a3852dd6793e20fa210cccf4.jpeg

Here you go.
I want to Make a reference of the character i currently using :smiley:

I’m going down this rabbit hole in blueprints. Unfortunately your solution requires the child actors to be spawned. The need is to do this without spawning the children. Is there a way?

If the actors are already spawned into the world, you can use “Get All Actors of Class” and select FatherWeapon.

If the actors are not spawned into the world but you still want to get a reference to them, it’s best to use a Structure, DataTable and Function Library in combination. This is the best solution. You can either search for this on YouTube or take a look at https://gameinstruct.com/ - Good resources there as well.

Here is an example of how I used it for my game:

  1. I made an ItemInfo structure:

  2. I made the ItemInfo Data Table and added all the information for every single item

  3. I made a Function Library and added the ItemInfo function in there:

  4. Now I can use the GetItemInfo function I made in the function library anywhere I want. I just have to give it the item name and I can get all the values for that item (which reads from the data table):

Thank you so much for this! Possibly a noob question here, seems like a chip shot now, but once we have this set up, is it possible to for-loop each row and return matching results? A few use cases:

I want to for-loop through all rows in the data table and return , for example, all classes that have variable X Y or Z.

Return all Classes that have rarity Poor

Sum the values of all “Weight” variables.

I may just have to try this to discover what method would work.

Thank you again for doing this!

Yes that’s also how I use it sometimes. Let’s say I have the Item Type “Animal” and I only want to do something with those items:

Kind regards,
Moustafa Nafei

1 Like