Get all actors of a class

Hi ,

dumb question alert …,

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

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 … …as shown in a screen capture of the print result i took below…

…Thanks for any help appriciated in advance …

weird. each instance is running the for loop so i’d expect 3 groups of three, but seems like you have six groups of 3 so that’s odd. maybe the both the parent and child begin plays are executing your loop

Hi…,

Yeah …Sorry it was probably because of compiling and saving timing between BPS ,…So now i’m getting 3 groups of the 3 knight actors , …but isn’t that still weird i mean shouldn’t i get only one group of the 3 knigth actors where it should just print 3 elements …correct me if i’m mistaken …cause this is waht i believe the correct print result should be…

Each dark knight is separate instance and will fire its Begin Play separately, you should see 9 Prints here. If you see more, then it’s weird.

If you put this code in the Level Blueprint, Game Mode or any other framework classes, you’ll see it print 3 times.

Hi…thanks for your help …

…actually the code is inside the “knight_Dark” pawn itself which is the child of dark piece class which is in turn a child of piece parent class …

But shouldn’t be reasonable to see just 3 elments imean i have 3 khignts and the "get all actors of a class " node should return 3 actors since i cut off all the parents to children begin play connections so that it is not doing it over and over again …shown in picture below

what i want is i have 3 knights on the board i should only get 3 actor references to them …

IndieGameCove is right up there.

Get All Actors Of Class runs 3 times, each time detecting 3 knights. Each knight prints 3 times because you run Print String in a loop.

Thanks for your response …So now to the point what should i do to get just the 3 knight actors once from “Get all actors of a class”…i guess i don’t have to run the print string in a loop …but if i run it from loop completed it prints just the latest knight “knight_Dark 3” in the same fashion 3 times… So is there a way …???..thanks in advance.

Put this code in the Level Blueprint, Game Mode or any other framework classes, you’ll see it print 3 times only.

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…

It has less to do with child-parent relationship and more to do with instancing. I guess it’s all related in a way.

Blueprint is an object template. When you spawn it, you create an instance of that object. This object will have its own set of variables and functions as declared in the template. It will live its own independent life from now on.

In your case, each knight reported how many knights there are in total. Each counted 3.

When it comes to child blueprints, think of it as a template extension.

You have the parent class that does all the shared, mundane stuff:

  • have mesh
  • be clicked on
  • can move
  • bunch of variables

And the child class defining the details:

  • which mesh
  • what happens after the click
  • if I can move, how do I move
  • more variables the parent does not need to worry about

Actually " Eveynone " you were right on your answer from the beginning …i didn’t get it when you said Quote “If you put this code in the Level Blueprint, Game Mode or any other framework classes, you’ll see it print 3 times " so i thought 3 times means 3 groups of 3 knights printed …but it was just 3 individual knights …
…So i consider your answer as accepted the same as” IndieGameCove " which points to the right solution also …

Thanks both of you …best wishes.


Actually i didn’t see your latest explanation commented …very descriptive and informative i thank you for that …hence that brings a question to me …

.Here where it comes my question how to reference each actor seperately from inside the child actor itself which is back to the same what i was trying to do here

…for instance if i want all the chess pieces to move it should be coded in the parent piece like a timeline or something to make the pawn move …
…but then if i want the knight piece to move differently from the king piece it should be done on a sub level i mean within the knight child piece or the king child piece …

…the issue here i’m having 2 knights on each side and 2 rooks and 8 pawns (i mean “chess pawns” here) and so on …but i made only one blueprint child for each piece and i’m not spawning them at runtime instead they are instances placed before hand and i did set their locations from the tiles positions on the chessboard actor construction … …

…for instance if i want all the
chess pieces to move it should be
coded in the parent piece like a
timeline or something to make the pawn
move … …but then if i want
the knight piece to move differently
from the king piece it should be done
on a sub level i mean within the
knight child piece or the king child
piece …

That’s one way to do it, sure:

Base Class has a timeline and an empty function:

Child runs the parent’s Timeline onClick and overrides the function with it’s own movement method:

Do note I’ve never made a chess game, but the approach seams feasible.

…Thanks for that , very interesting way to do it , …there is one thing i’m stuck on right now , i know nothing about it… and i really need help with ,…
…i’m confused about the player controller cause this chess game consists of 2 players…

…since i don’t have 2 Controllers to test it… just a mouse and keyboard…how to develop the game with just mouse clicking but then make it suitable for 2 players…by adding 2 player controllers i guess…

…for now i’m just using the mouse click on everything , …how to enable and disable the mouse clicking on moves…???..

…1- So how to separate dark pieces from bright pieces and decide the turn of each side… is it through player controller index 0 , 1…or disabling input on pieces …???.

…2- How to prevent the player from clicking anywhere except on the allowed moves tiles on the board …is it by adding the clickable tiles to arrays and then…???..as far as i know switching on Enum see picture below …

Note : i’m in “FirstPerson” project i did create a new GameMode and attach a new player controller to it , but the pawn still the default pawn Since i’m not possessing any chess piece pawn class …

…Yeah that’s right… is what i didn’t notice from the beginning…