Get all actors of a class

Hi ,

dumb question alert …:cool:,

I have setup up this hierarchy of Pawn classes : Chess piece parent ->Dark Piece -> Dark Knight …So the “Chess piece” pawn class being parent of the “Dark Piece” class and the latter being parent of the “Dark Knight” class …all good …:D…

the funny part here when i put 3 instances of the “Dark Knight” class ,and run get all actors of class (“Dark Knight” class ) in its event graph and print the “for each loop” , i should get only 3 actors , but instead i’m getting the 3 actors multiple times …:confused: …as shown in a screen capture of the print result i took below…

…Thanks for any help appriciated in advance …:slight_smile:

You seem to be executing the Loop in the Dark Knight Blueprint (it says knight_dark > Event Graph at the top).
That means it executes the Loop an all three Dark Knights (all Dark Knights iterate over all Dark Knights)

thank you for your helpful response …and yeah i just discovered that it should be performed from let say a game mode to give just 3 knight actors printed …

So here where i ended up …i just did the same for each loop in the game mode event graph …and surprisingly it gives the desired results it is actually printing just 3 actors as shown below in picture attached…

What i learned is that you can’t get just the 3 actors printed as a result of “Get all actors from a class” node from within the child actor itself ,it should be from a framework bp like a player controller or a Game Mode …

just if anyone could confirm this is right for me …to take it as a rule throughout my learning process…cause i’m having a hard time understanding the parent to child relationship.

Here is actually what i’m trying to do : https://forums.unrealengine.com/development-discussion/content-creation/1507512-getting-a-separate-references-to-instances-from-within-the-actor-bp

This is nothing to do with parent-child relation or inheritence. You simply run this code three times and it returns the proper values 3 times. But this could be a completely seperate actor without it being a child and three of those would do the same. (getallactorofclass in drak_knight could make sense for example if its not event begin play but a custom event, maybe activating an ability that gives buff for all dark_knight units)​​​​​

And yrah if you want to get a reference for each unit than you should have an array of units in gamestate or gamemode and add new units to that array upon construction or begin play