I’ve been working on a project for a few weeks now. When hitting playmode on the project, a few times in a row it will work fine, but randomly the play mode will just fail. It will freeze Unity or display the “Hold On” message, which will just keep going infinitely. I know there’s no infinite loops because it will build fine once I force close Unity and reopen the project. I’ve never had this issue before until this project, can someone help me figure out what’s going on?
Just because it sometimes runs fine, doesn’t mean it for sure isn’t caused by an infinite loop. I ran into an infinite loop one time in my own game that was very timing sensitive. I don’t remember exactly what it was, but I believe I was expecting something to happen by a certain amount of time into the game, and would get stuck in an infinite loop if it had not happened yet. Most of the time it had happened, but if the CPU was particularly bogged down when the game started then it wouldn’t happen and then infinite loop. I remember having to spend the better part of a couple days to track down the source because it was hard at first for me to reproduce on demand, and was more likely to occur on certain computers than others, so it felt more hardware related or a Unity bug. But nope, infinite loop.
I believe I found it by literally putting Debug.Log statements into every While loop in the entire project. Though using a debugger probably would have been a better idea. I cut back on using While loops after that one.
You were exactly right. I went through all the loops in my code and found that one in particularly was causing issues. The project is running well now, so thank you!