Other way than using Get All Actors of Class to set variable

I use the basic first person shooter example map.

I have made a blueprint “tester” that is a cube that rotates. It gets spawned in the level by the level blueprint.

In the firstpersoncharacter blueprint i made a linetrace so that if i shoot one of the white cubes that are already in the level (staticmeshActors) the cube stops spinning.

I am using “Get All Actors of Class” to set a variable “spinning” inside my tester object to false.

Is there a better way to do this instead of “Get All Actors of Class” to set that variable “spinning” that is inside my “tester” blueprint? (tester blueprint) (first person character blueprint) Level blueprint

Cast Hit Actor to Tester -> Set Spinning

I already have a cast to StaticMeshActor because with the line trace i want to hit the WHITE BOXES but i have to set a variable tester blueprint.

I tried like this but it does not work.

The *tester *is your white box, right? Connect the Hit Actor to the missing object pin on your cast, as suggested. You do not need to cast to the static mesh.


To be more clear. Tester is a blue box blueprint that i spawn with “code” inside in the “level blueprint”. In the tester blueprint there is “code” that the cube keeps spinning and a boolean variable that decides if the cube keep spinning or stops called spinning?

When i hit one of the white boxes with a raycast (boxes that are already in the standard first person example level and are static meshes). Then the **blue cube **should stop rotation.

So hit actor should be connected to “Cast to static mesh actor”. Because the white boxes are static meshes and i need to linetrace them.

But i need a way to get to the spinning? variable inside the “tester” blueprint to make the cube stop spinning when a raycast is succesfull on a white cube.

Now i use GetActorsOfAllClass to get to the tester object and set the** spinning?** boolean.

Is there a better way?

How do we know which blue cube is connected to which white cube? How are they connected / related?

Is this like a 1:1 relation? *This *actor talks to *that *actor and that’s it? It’s fixed?

Or are there rules connecting them? The cubes have names / IDs / a random factor / ascending order / proximity?

If you are only stopping the rotating cube once then I would imagine the way you are doing it is fine.

If I had multiple blue rotating cubes which I wanted to be able to start and stop rotation from the player controller I would

  1. Create an event dispatcher in the player controller with a bool parameter for rotation control.
  2. Add an event(A) in the blue cube which with player controller input param, binds the event dispatcher to an event which sets cube rotation.
  3. At begin play in the player controller get all blue cube actors to call the event(A).
  4. Then all you need to do is call the event dispatcher in the player controller to start and stop cube rotation to your heart’s content!

I think that makes sense, don’t know if this is making it more complicated than it needs to be, but its a fun way to do it!

You could also make every blue cube find the player controllers then bind themselves to the event dispatcher. But this will only work assuming he Player controller is defiantly spawned in before the boxes beginplay is called! :slight_smile: