Understanding accidental infinite loops.

Hey there,

I’m trying to understand infinite loops.

I have a setup that feels fairly simple.
The character creates the spawner, the spawner creates the floor.
(The floor is a child of the spawner, as is a few other bits)
Done.

But for some reason, the spawner to floor relation just explodes.

There are loads of posts about infinite loops, but I just can’t seem to find a relatable answer.

Thanks for reading.

Additional:
The infinite loop seems to be more of a maximum call stack or something.
But I’m not seeing why this should constantly begin playing.

I managed to stop the infinite loop by using a bind event instead, but now it creates bind twice.

Not sure if this is related to loops. But connecting up this “spawn actor floor” makes the “begin play” go through a second time? Weird.
1.not connected result
2.when connected result

However, the “spawn actor floor” does only trigger once. Shown here.

Is this just a weird bug of unreal?

1 Like

Seems a class is spawning recursively. It’s a bit hard to tell from the collage.

Use a breakpoint at begin play to follow the execution flow.

1 Like

Typical :grinning:. You need a condition that breaks the loop.

  1. Create a boolean variable, initial value is FALSE
  2. If your loop starts, test this variable.
    2a: if TRUE: Stop. Don’t execute the loop. Exit the loop and set it to FALSE
    2b: If FALSE: Execute the loop, set variable to TRUE

Another option is a FOR loop, run from 0 to 1, or any number you want the loop to be executed. This implies the previous code (so don’t ■■■ this)

A good example is the construction blueprint script to create a spline - examples enough on the internet.

1 Like

Thats a great idea.
I need to quickly just read up on breakpoints. I’ve not used them so much, so I’ll need to do a few tutorials on how to properly use them.

Interesting.
I’m not seeing where the loop is to break?

Sorry If I’m slow to respond, I’ve got to rush out to work for the evening.
Thanks for the responses. I’ll look into both of these and get back to you.

Just right click on Begin Play and Add Breakpoint. On Play when it breaks there will be some arrows at the top; click the right arrow to go node by node.

You’ll find the loop when it start to repeat after a spawn node.

About breakpoints: https://dev.epicgames.com/documentation/en-us/unreal-engine/blueprint-debugging-in-unreal-engine

1 Like

I think the best place is directly after beginPlay event, as that seems to be the location where BindEvent is referring to. Or just before BindEvent is called.
Another option is, if code is to be executed multiple times, define it as an integer, set it to the number of loops - 1, decrease the variable on each loop and break it when it reaches zero. the advise to step through the code is valid - it can show you the place where the loops needs to be broken.

1 Like

Sorry this is a late reply, work has been manic.

OK, so I’ve played with breakpoint, which I gotta say is a wildly sick system to have. So thank you for making me aware of it. It’ll solve a lot of issues.

It seems I’ve ended up here with this, creating an infinite loop.

To test this, I created 2 blueprints.
One being just empty and one being empty but a child of spawner.

The child gets the infinite error, the plain actor doesn’t.
(So floor being a child of the spawner errors)

So I guess my last question is why do my child blueprints loop?
If its confusing this is a layout of how the very small world is spawned and made


teh character hits player start, creates the spawner(isnt a childbp of the character), which then creates the floor etc(which are childbps of the spawner)

Yeah I threw in a bind to kill the infinite loop but I think it actually just fractionally masked the infinite and left me chasing ghosts. Ive removed the bind and Im back to infinite loops.

Urgh… sigh… I’ve figured it out.

I apologize for wasting people’s time, It turns out I’m an idiot, I didn’t fundamentally understand the parent/child relation.

My floor being a child of the spawner meant it inherited everything…like everything, It’s essentially an instance to some degree, a duplicate.

So the spawner spawning its child creates a loop as the child restarts the spawner etc etc.

Man…unreal humbles as always.

Learning how this system works plus the breakpoint has been a huge jump forward.
Thanks for reading and taking the time to help.

No problem. Don’t blame yourself, everyone makes mistakes, even seasoned programmers.

1 Like

I managed to stop the infinite loop by using a bind event instead, but now it creates bind twice.

Yeah, I did exactly the same and was getting the same result. Mine was due to a child blueprint of the spawner.

I solved/bugfixed this by removing the bind fix and just going back to the infinite loop and really looking through on why I was getting an infinite loop.

If youve got some images or something, could probably have a look through it?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.