Skip to content

Commit 7953c44

Browse files
authored
feat(Unity): Updated ANR detection explainer - Single vs Multi Threaded (#14834)
There is a difference in how the integration works based on whether the SDK can make use of multi threaded - or not.
1 parent 93e845b commit 7953c44

File tree

1 file changed

+16
-3
lines changed
  • docs/platforms/unity/configuration/app-not-responding

1 file changed

+16
-3
lines changed

docs/platforms/unity/configuration/app-not-responding/index.mdx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,23 @@ Application Not Responding (ANR) errors are triggered when the Unity thread of t
88

99
## ANR Implementation Details
1010

11-
The ANR detection in the Unity SDK strictly works within the Unity game, irrespective of the targeted platform and works in two parts. First the SDK starts a coroutine that periodically notes the time it last got called. Second, a background thread checks the time since the last update against the ANR threshold from the options.
12-
The detection is sensitive of the app losing and regaining focus and gets paused accordingly. It is also using `WaitForSecondsRealtime` so pausing your game by modifying the `Time.timeScale` will not trigger false ANR reports.
11+
The ANR detection in the Unity SDK works differently depending on whether multithreading is available on the target platform:
1312

14-
On platforms that do no support multithreading the ANR detection falls back to relying on the coroutine itself to report if the last time it executed exceeds the timeout.
13+
### Platforms with Multi-Threading Support
14+
15+
On platforms that support multithreading, the ANR detection works in two parts:
16+
1. A coroutine periodically resets a counter
17+
2. A background thread increments and monitors this counter. It reports an ANR event when the threshold defined on `options.AnrTimeout` is exceeded
18+
19+
### Platforms without Multi-Threading Support - WebGL
20+
21+
On platforms without multi-threading support like WebGL, the ANR detection uses a slightly different approach:
22+
- A single coroutine using a `Stopwatch` to measure elapsed time
23+
- When the coroutine detects that more time has passed than the ANR timeout, it reports the ANR event
24+
25+
The drawback here is that the ANR detection relies on the game recovering from the not-responding state to report the event.
26+
27+
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.
1528

1629
### Stack Trace Support
1730

0 commit comments

Comments
 (0)