- Home /
How to identify a freeze bug?
I am currently encountering a tough to identify bug in our game.
When I run the game in Unity it freezes over.
There are no errors on the Console before the freeze
The memory usage is around 350 Mb – 400 Mb and no high CPU usage
The freeze happens in various stages of the game. Sometime it is at the start sometimes in is in the middle or at the end.
I am finding it hard how to identify the cause of this error. Is there any method I can follow to get a clear idea what may be causing the problem?
Are there any tools I can use to figure out what is happening in the game?
Do you have Pro/ Profiler access?
During these freezes what does the stats page say in terms of Draw calls, Tris etc?
Perhaps some way of placing breakPoints in the code? The best assumption that I can come up with is some for/while cycle that doesn't stop for some reason.
It's probably an infinite loop somewhere. Try to identify which gameobjects (and consequently, which scripts) are active when the freeze occurs. What script might it possibly be in the middle of executing? Is there an execution order, either explicitly set on the scripts, or implicitly because of the structure of your code? If so, put calls to Debug.Log in each step and pay attention to the console to see how many of them go through.
Repeat NullRefs in Update do not constitute a freeze. The game is still technically running; Unity's runtime just prematurely aborts execution of the Update that contains the NullRef. This may trigger an avalanche of other exceptions later in control flow, but as long as the program state allows Unity's runtime to pump frames, it isn't technically frozen. The performance hit is probably due to the sudden added overhead of writing a massive amount of exceptions and attached callstacks to the logfile, and if IO can't keep up with that, the device might ter$$anonymous$$ate the process, I guess.
I maintain this is an infinite loop somewhere that causes it to get stuck in the frame it is currently rendering.
Question: When this happens in the editor, does it freeze the entire editor, too, so you have to restart Unity?
:P I didn't say every NullRef causes a freeze. I said repeat NullRefs CAN grind it to a halt resulting in a freeze then crash :) And it's very common.
Whereas you speak the truth in the technicality of the NullRef I'm simply stating an observation, and a frequent one at that.
If my game has frozen up and/or crashed ~80% of the time its a NullRef error and it's a NullRef that doesn't show up in Console. In fact (for Android) a lot of them I've only spotted through LogCat.
Answer by whydoidoit · Oct 17, 2013 at 12:04 PM
Attach MonoDevelop to the process and click "Pause". See where the code is in the call stack.


When this happens to me it's nearly always a coroutine that has a section that doesn't yield for some reason.
I have following question,
Let’s say unity is executing function A in class X, While it is doing that is it possible to receive an OnTriggerEnter event to class X ?
No. The thread that executes function A in class X is the same thread that would call the OnTriggerEnter event, and one thread cannot have control flow in two different places simultaneously.
I have following question,
@wijesijp Submit as a separate question.
Add some closure to this one. Was your problem solved?
The problem is still there. I am trying to figure out why it is happening. I followed your suggestion but there is no output in call stack.
Answer by ToneDP · Jan 17, 2019 at 11:13 PM
Love this answer, but I am unable to get the new Visual Studio for Mac to pause any Unity app under any conditions, though it does attach to the process.
Your answer