x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 ....

alt text

alt text

Product Version: UE 4.19
Tags:
more ▼

asked Jul 27 '18 at 06:09 AM in Blueprint Scripting

avatar image

Carter10
19 2 6 12

avatar image IndieGameCove Jul 27 '18 at 06:26 AM

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

avatar image Carter10 Jul 27 '18 at 07:03 AM

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.....

alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 27 '18 at 07:14 AM

avatar image

Everynone
13.7k 74 25 57

avatar image Carter10 Jul 27 '18 at 07:32 AM

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 ..

alt text

alt text

avatar image Everynone Jul 27 '18 at 07:47 AM

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.

avatar image Carter10 Jul 27 '18 at 08:03 AM

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.

avatar image Everynone Jul 27 '18 at 08:37 AM

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

avatar image Carter10 Jul 28 '18 at 02:32 AM

....Yeah that's right.... is what i didn't notice from the beginning...

avatar image Carter10 Jul 27 '18 at 08:40 AM

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...

alt text

alt text

avatar image Everynone Jul 27 '18 at 08:51 AM

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

avatar image Carter10 Jul 27 '18 at 09:36 AM

... 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 ........ ....

alt text

alt text

chessboard.jpg (208.5 kB)
avatar image Everynone Jul 27 '18 at 10:54 AM

....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:

alt text

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

alt text

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

capture.png (85.0 kB)
capture2.png (162.5 kB)
avatar image Carter10 Jul 28 '18 at 02:29 AM

...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 ...

alt text

switch-on-enum.jpg (164.8 kB)
avatar image Carter10 Jul 27 '18 at 08:56 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question