App Not Responding (ANR)
Learn how to turn off or specify ANR.
Application Not Responding (ANR) errors are triggered when the Unity thread of the game is blocked for more than five seconds. The Unity SDK reports ANR errors as Sentry events.
The ANR detection in the Unity SDK works differently depending on whether multithreading is available on the target platform:
On platforms that support multithreading, the ANR detection works in two parts:
- A coroutine periodically resets a counter
- A background thread increments and monitors this counter. It reports an ANR event when the threshold defined on
options.AnrTimeout
is exceeded
On platforms without multi-threading support like WebGL, the ANR detection uses a slightly different approach:
- A single coroutine using a
Stopwatch
to measure elapsed time - When the coroutine detects that more time has passed than the ANR timeout, it reports the ANR event
The drawback here is that the ANR detection relies on the game recovering from the not-responding state to report the event.
Both implementations are sensitive to the app losing and regaining focus and get paused accordingly. They also use WaitForSecondsRealtime
so pausing your game by modifying the Time.timeScale
will not trigger false ANR reports.
Since the ANR integration creates an exception on a background thread, based on a coroutine not resetting in time, the stack trace will not show the main thread's stack trace.
Since the Unity SDKs line number support is limited to actually thrown exceptions, the integration does not provide you with line numbers in the captured ANR issues.
ANR detection is enabled by default in Sentry, but you can opt-out through the editor window by going to Tools -> Sentry -> Advanced -> ANR Detection
. You can also set the ANR timeout there.
You can also opt out by disabling the integration.
options.DisableAnrIntegration();
To set the timeout use the following snippet.
options.AnrTimeout = TimeSpan.FromSeconds(5);
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").