Moving items in a Loop
I'm trying to create a mechanic where i have a staircase that's flat, and once an event is triggered the staircase will rise
Right now i just have a construction script with a forloop that lets me create a modular staircase
the issue is trying to move the steps with an event. The only way i've found it to look like what i want is by replacing the steps, although it adds steps every frame then. I've tried just setting the worldlocation, although it doesn't move the steps then. i'm not sure if there's a way to move static meshes created by a forloop
(sorry for the poor gif quality, i had to optimize it heavily just to upload it)
and thank you for any help
Evigmae is right that using a complete staircase mesh, and updating (animating) the Z-scale, would be much simpler in terms of blueprint scripting.
But maybe you need staircases that span longer and shorter distances, and staircases therefore need to be adjustable in the editor. Or maybe there's some other reason why you definitely need to procedurally create and animate the individual stairs.
If that's actually the case, you're going to want to start by thinking about your "spawning" and "animating" actions as completely separate. As you already pointed out, you definitely don't want to be spawning in multiple stair meshes every frame.
So, basically, create the stair meshes just like you already showed in your first image — this is the "spawning" step taken care of. But you should then also keep track of these stair mesh components (store them) in an array variable in your staircase blueprint for easy access later.
Then, when the staircase is triggered to rise (which can be done multiple ways, and is entirely up to you), an event is executed on the staircase blueprint (which you will also need to set up) that causes each individual stair component in the array to begin moving.
You should still be able to use the Timeline node you have to make the movement work; just toss a ForEach loop after the Update pin, and multiply the Timeline's output by the index of the item in the loop.
There are a few details I left out, but hopefully this makes enough sense that you can put it all together and get it working.
Best of luck!
answered Jan 03 '19 at 05:10 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here