Infinite Loop

Hello, so I’m trying to make a simple game where you can spawn an apple somewhere in the map (it’s a 2d game) and the player moves to it automatically. I’m using a while loop and a compare float to move to the left or the right, depending of the position of the apple or the player, but whenever I hit play the console says it detects an infinite loop. I don’t get why my blueprint is an infinite loop :s

Its an infinite loop because the engine can’t know that Input will ever == ApplePosition. Also you need to be prepared for the very real possibility that this solution will overshoot the apple between frames. I think you want to look into pathfinding and nav meshes to move your character to this apple :slight_smile:

While loops work between frames so your setup could never work. Basically he while loop if running the script so many times between a single frame that it considers it a endless loop. Since your trying to create movement by checking a value then doing a action then repeat, ie looping the script then i would do just that. Replace your while loop node with a branch then at the end of the script after the move call your gotofood event. This will cause the script to loop as intended until the bool is false. Also you could eliminate the bool and just have nohing after the == output. That would also break you out of the loop

maybe saying between frames isn’t the right way to put it, its more like execution stops until the loop finishes.

Hey, you could use you current logic, but just put the event on a SetTimerByEvent node. That way you can make the search and correct only happen every .1 seconds, or so… :slight_smile: