How Can I get the "WhileLoop" working?

I’m trying to use the while loop in a simple script but I get the message :

LogScript:Warning: Runaway loop detected (over 1000000 iterations)
MyProjectile_C /Game/Maps/UEDPIE_0_Example_Map.Example_Map:PersistentLevel.MyProjectile_C_8
Function /Game/Blueprints/MyProjectile.MyProjectile_C:ExecuteUbergraph_MyProjectile:001D

I simply want it to execute every frame while a boolean var is true… but it doesn’t look like I know how to properly use it…

The while loop will continue to execute within the same execution tick.

What you want to do is hook up an OnTick event in your Actor blueprint and then have a Branch based on your boolean var.

Ah ok cool I get it, thanks for the quick answer!

Can I request that a Blueprint function be made like the “LoopWhile” one, but only executes every tick ?

+1 on this. In its current state the while loop seems to just be a big fat crash button.

The WhileLoop is working as intended, just some case needs to be taken to ensure it is being used correctly.

Note in the documentation for [WhileLoop][1] where it states:

As with While loops in programming
languages, extra care must be taken to
prevent infinite loops from
occurring.

Namely, if the logic executing in the while loop never sets the condition controlling the while loop to false, it will never stop executing, and you’ll run into problems.

I think the functionality you’re looking for in regards to something that executes once per Tick is represented by the Tick Event. If you want a function that executes exactly once per tick, you could easily accomplish that by connecting the “Event Tick” node to a function you make in your Blueprint, like so:

5436-tickfunction.png

You can also execute a function once per tick as long as a condition is true:

5437-tickfunctionwhiletrue.png

Are you having trouble getting the results you’re looking for from the Event Tick node?

You could add a small delay in the while loop so that it only executes once per frame. Hacky, but could get you what you want without crashing. I know in other scripting languages there was a command for “waitframe();”

Using tick would work, but if you’re looking for this functionality and you’re already doing a few things with the Tick event, it can get kind of messy.