Play timeline inside ForEachLoop

Hi, I need to move n objects at the same time using 1 timeline, this to avoid copy-paste the same timeline n times for every object I need to move

So this code is not going to work, cause from what I understand the timeline can be played only on 1 object at time, and this code is trying to play it on several objects one after another, is there a way to archive this? Seems like a solution was given in [this][2] post but image link is gone.

1 Like

This works if all my objects are in 0,0,0 I guess, in my bp all my doors are in different locations and I need to set the “Initial Location” for each one before start the timeline. Does this other methods allow me to animate my door with a curve like timeline?

below is another method you can try. it seems to work as you want in my initial testing. in the example we use a map instead of an array. the map will store the components to be moved and their associated initial relative location. as you can see in the picture when the event is called we first get all the components to be moved (i was getting all children in this case). then we use a for each loop to add the components to the map and at the same time get eaches location ans set that to the map as well. once we have created and populated the map we move on to moving the components via a timeline. to move each component we get an array of the keys it contains then use a for each loop as before to set the location. in this case however we are also getting the relative location associated with each key via the find node and using that as a reference point in the lerp.

this should all work as you like but i would caution that if you have many of these actors in your level then this may not perform well due to having so much to calculate each frame. if you only have a few of these actors it should be fine though and really it comes down to your target and optimization.

2 Likes

oh and in your post you mention using this for doors. im guessing that your trying to do something like reset all the doors or open them all at once. if thats the case you could have each door as its own actor which would make things simpler, then you could use a event dispatcher to initiate each door to open or close itself. if you dont know about event dispatchers theres a great video by epic about blueprint communication which teaches all about it.

Thank you very much for your help!

loops run between frames so running a timeline in a loop wouldnt work. you could however use a for each loop after the timeline to set the location of many objects. or you could use one of the many other movement methods such as interps or add offset.

5 Likes