Basic Loop Question

Hey guys!
Pretty new to this whole blueprint thing, and I was just wondering if someone know how I could run this blueprint in a loop?
What the blueprint does is spawn a static mesh I made, and then it moves it from the right to the left. What I would like it to do is spawn the mesh again after x seconds.
I’m pretty sure this is doable, but I cant figure it out.


Thanks for any help guys, and sorry if its a stupid question :slight_smile:

Use “Add Local Offset” node instead of your function, it’s much more convenient :slight_smile:
Check out this Playlistfrom Epic and this for Blueprint Essentials
For loop use “For Loop” node :stuck_out_tongue:

A loop for such task would freeze everything else.
For smooth movement or value changes use interpto.
In your case: either destroy your used mesh and then spawn new one in start position. Or simply change location vector of mesh to starting point.
Condition for this could be seconds that passed from spawn, or location it reached (eg, x>20000).

First of all, thanks for the replies guys! :slight_smile:

I will definitely check out the youtube videos you linked me to zeOrb, thanks! I’ve tried using the “Add Local Offset” node, but it doesnt quite work with the blueprint (I made a new one btw).

And Nawrot, why the heck havent you told me about interpto before? :stuck_out_tongue: (aka thanks for pointing out that interpto existed) It made my life a lot easier, in fact I made a new blueprint using interpto to achieve almost the same effect.

My problem now is that I cannot figure out how to asssign a random z value to the spawned location of the mesh. If I try to assign a random z value, the mesh jumps up and down when I play (probably because its getting a random z value every tick, and therefore changing the z value on the fly?) So how would I go about giving it a random z value at the spawning location?

Also I’m gonna try to get more into the loops thing, but at the moment I dont understand much of the forloop etc. But is this new blueprint loopable without freezing everything?


Again, thank you guys so much! Im pretty new to this, so getting some help from guys like you really motivates me to continue learning!


Your blueprint is not really good.

You have event tick, this is ok for your movement… but you actually start a delay every tick as well… which means that you have a ton of “threads” running at the same time(not real threads, but…).

You delay for the destruction should start on the creation of the mesh… or be triggered when you want it dead. Now what I think you are trying is to kill it after 3 seconds, so in that case I would start the timer on construction of the object.

As for your use of interpto. You’re doing it wrong :slight_smile:
What you are doing is working. But, you are constantly changing the starting point of your interp so when you get really close, it slows down. This might be what you want, but it is “wrong”.
The “right” way is to store the start location in a variable and then use that each tick.

Your way works, and you might want the effect. But there is an important difference in the two cases.

As for the jumping up and down. It is certainly because you are getting random z every tick.

Just have 2 different “make vectors”. One for the begin play, and one for tick.

Here, I’ve made an example for you. This shows you how to correctly create your object and prevent too many delays running and it takes care of your jumping up and down.


Thanks man! I tried setting up like you did (I had to change some x,y and z values) and it worked, but it didnt move the object from right to left, so I added some modifications, and here is what I came up with.
Its probably just as bad as the 2 first ones I made, but if its allright, would it be possible to run this in a loop, and if so how?

Sorry for such noob questions, new to this. But its still pretty fun to learn while doing these kinds of stuff :slight_smile:


No… you can’t run that in a loop.

You would have to build some kind of controller Blueprint to spawn a new mesh once in a while.

But you wouldn’t use a loop for that either… not the loop node anyway.

You would use on begin play >> spawn a mesh/blueprint >> delay
From the back of delay you would drag to spawn node… then you have a delayed loop… but without using the loop node.
That would be how you’d do it.

I recommend that you follow the tutorials from Epic on Youtube. It covers a lot of the basic stuff I’ve been telling you here.

To avoid having to get the World Location every time, you could restructure your Components. As the Root component, use the “Scene” option at the very bottom of the add components list. Scene is nothing, just something to use as a fixed point. That way, you only have to set the relative location of your actor using “Set Relative Location”. It saves a few steps.

Also, if your delay is fixed and won’t change, you could use a Timeline to handle the movement. A Timeline can be set to loop automatically. In that case, your blueprint would consist of three nodes; Event Begin Play->Timeline->Set Relative Location

To create a Timeline, add the node (right-click, bottom of the list). Double-click the new node and a Timeline window opens. Click the “V” button to add a vector track. Since you seem to want Y-axis movement only, click the little green checkbox (Y is always green). Next, you’ll add keyframes to set how far the actor will move over a certain amount of time. You can even tweak the curve to make it ease-in or ease-out as the actor “lands” in its final position.

You have two options when it comes to setting up the keyframes: A) You can simply do 0.0 - 1.0 and add a scalar vector to the output of the timeline (allows you to set the distance without editing the timeline), or B) just set the distance directly in the timeline (-3000 in your case). I suggest using the 0.0-1.0 option. To do that, shift-click anywhere on the timeline to add a keyframe. While that keyframe is selected, you can edit its “Time” and “Value”. You want the first to start at 0.0, so the Time is 0.0. Set the Value to 0.0 as well. Shift-click to add a second keyframe and set the time and value both to 1.0. A third keyframe will control your delay. So shift-click again, make the time whatever you want for a delay +1 (taking into account the 1.0 of movement). Finally, at the top of the Timeline window, enable the “Use Last Keyframe” and “Loop” options. You’re done with the timeline.

Plug “Event Begin Play” into “Timeline:Play”, Plug “Timeline:Update” into “Set Relative Location”. Drag the variable for the component you’re moving into “Target”. Connect the “Timeline:New Track” output to a “Vector*Vector”, then on to “New Location”. On the multiplier, set Y to -3000. That should do it.