Download

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: