How can I call to all actors in a array at the same time ?
By hitting a key I can call to let`s say index 0 in a array, connected with a “get”-node.
But I want to call to all index characters that are stored in the array.
How can I call to all actors in a array at the same time ?
a sequence node or for loop
I have built this one here but I get some errors.
You see in the left corner a variable with my two actors which I want to call at the same time.
Everything is okay if I go straight into the “get all actors of class” node and choose under “Actor Class”
the movinglight, BUT I have two or more actor classes.
It’s hard to follow exactly what it is you’re trying to do. A better explanation of the problem would help. If you’re trying to loop over all instances of two different types of classes, then All Moving Lights should be an array of classes, not an array of actors.
Okay let me try to explain a bit better:
I have two actor classes, movinglight 1 and movinglight 2, and from each of them I have 2 instances in the level.
The reason for 2 movinglight-classes are different target points, so every class has its own target point to look at.
But for all movinglight-classes I want to switch the color by hitting my “h”-key, it should be a global setting for all movinglight-classes.
With only one movinglight-class in the level everything works, but by having two or more classes only the first one are changing the color.
So I have to call all classes together with one hit on my “h”-key but I don´t know how.
Hmmm… what warnings/errors are you getting? I built something in V4.7 and it doesn’t have any problems.
I have built your setup exactly like you did and that works.
On the next screenshot below you see my current setup that works for one movinglight class in the scene.
I have marked on the left side the actor class I can choose and on the right of the next node “array Element” output pin. In your case this pin
is an array output pin (from the “Get all Actors of Class”-node) where I can not connect all the lines to the target nodes, which looks a bit messy
in the moment I think.
Any idea ?
Thanks a lot.
so you want to grab all the actors of multiple classes and do the same thing to them?
if they share all the same things, are they child of another object? just search for all objects of there parent class and it will find them i’m pretty sure. (so just change the class in get all actors of class to there parent class).
i think what you are after in your example above is a nested for each loop, but i believe it wont work.
how do you have it set up?
Well it sure looks like it will loop over every instance. What makes you say it’s only working for one? Perhaps the data for the others isn’t properly initialized? Did you try putting breakpoints inside the loop?
So here comes all together:
I have created an actor blueprint. Inside are the meshes and materials of the movinglight.
In the construction script I placed two setups for dynamic materials -> see picture 1
In the event graph I placed the setup for looking to a target point, which is animated -> see picture 1
In the level blueprint I have 2 setups:
- by hitting “h” calling to the dynamic materials and the light color to switch the color stored in the variable color presets. see picture 2
- connect the target point with the movinglight so the movinglight looks all the time to the point. see picture 3
-Having lets say 15 movinglights in the level.
-Every movinglight is looking to his own target. (each target point is animated with a matinee timeline)
-All movinglights switch the color together by hitting the h-key like a global setting for movinglights.
What is the best way to do this ?
Once again, with only one movinglight in the level all works perfect with this current setup.
The problems comes up by having 2 or more movinglights in the level.
The reason it’s not working with with multiple classes is that for loop is that it won’t know what class it is, now directly after the for loop you could do a cast to the class that it might be and check each class. But that isn’t a good way to go about it.
I have a couple suggestions
I would suggest putting the event to move the lights in the moving light class. Then calling that event when the moving light button is pressed. If you want multiple actors of different classes to react to the same button press you could add an interface to those classes that you want to react. Where before I said add an event to the light themselves, make that an interface event and use that event in the moving light class. Then when the button is pressed use “Get all actors with interface” node, loop through that array and call the function you created for that interface event in each of the classes.
Second suggestion is you could create an event dispatcher on the player pawn or controller, or where ever you will press the button and simply class the event dispatcher when the button is pressed. Then in the classes you want to react to that event get the player pawn, cast it to your class then bind the event dispatcher event and create the even there.
Then the third suggestion is if these are just simple small changes in the same basic class, make a base Moving Light class, then make two more classes with Moving Light class as the parent. Then you can do get all actors of class on the parent class, and it will get the child classes as well. I would still suggest creating the event for moving the light in the Moving Light parent class. Then calling that event from the blueprint where you look for the button press.
There are a bunch of things that are setup wrong in those blueprints.
Picture 3, you have MovingLight plugged into Target MH, and the element from the ForEachLoop.
Picture 2 in the MovingLight event graph you have Update Rotation Event, which won’t have any target, you have Target MH which does nothing.
To fix that remove the MovingLight node from picture3, Remove Event tick and update rotation event from Picture2, and attach from Target MH Event to set world rotation.
I have duplicated the movinglight in the content browser, so I got 2 classes, movinglight 1 and 2.
I placed each of them inside the level and created 2 target points, both with different animations.
Then in the level blueprint I expand the setup for target look at, see picture 3, and it works for both movinglights.
So only the color switching section with my damned h-key will not run.
But should I use 2 or more classes ? If not, I have no problem with my color switching, but I need a way to give every
movinglight in the level his own target point to look at.
I see 2 ways:
one class of movinglights and every instance in the level has its own target point.
pro: the color switch works. contra: no idea how to give every instance a specific target point.
for every target point a specific movinglight class with an instance in the level.
pro: look at target point works for multiple movinglights. contra: the color switch works only for one class.
Simply add an actor variable to the movinglight class and make it editable. Then in the movinglight blueprint look at that actor variable, or get it’s location and set it to target location. Then when you place the movinglight in the level set it’s actor variable that you added equal to what you want it to target.
@darkhorror: I fixed the movinglight blueprint and the level blueprint for the look at target section, it works Many thanks.
@darkhorror: I added a new variable -> class - actor, to the movinglight. and then ? Because I have no so much experience on blueprints.
can you explain a bit more please ?
And this will be the result:
-only one movinglight class.
-for every instance in the level I can set a target point. Movinglight 1=target 1, Movinglight 2=target 2 and so on (instances, not classes)
The new variable you should add should be an Object Reference -> Actor
Then set it’s name, and set it to Editable.
Then place the MovingLight into the level, click on it and look at details, you will find the Actor variable you just created there. Then click the drop down menu and select the actor you want it to target.
To use that remove the stuff in picture 3, and in picture two change Moving MH, to Tick Event. And in picutre 2 for the find look at rotation target, get the Actor variable that you just created, and get location from that. Plug that into the target of Find Look At Rotation.
BAMMM, IT WORKS
Very very cool. Thank you very much for your help and support.
Now I can easily choose the target points in the editor for every single movinglight and have only one class to call for switching the color
for all movinglights together.
Again, many thanks to you.