Quick answer: An ANR means the app’s Android main thread did not respond to input for 5 seconds. In a Unity game that thread is usually waiting for the Unity thread during a pause, resume or plug-in call, or it is blocked by an SDK working on it. Get the ANR trace from Play Console or adb bugreport, read the main and UnityMain stacks together, and move the blocking work (saves, loads, SDK start-up) off those threads.
Android vitals shows an ANR cluster whose stack is all com.unity3d.player and framework frames, with nothing that looks like your code. That is normal for Unity, and it is why these are hard to fix by reading the top of the stack. Your C# does not run on the thread Android watches. The thread Android watches is waiting for the one your C# runs on. This guide covers what counts as an ANR and the Play threshold, how Unity’s two main threads block each other, where to get traces, how to read them, the causes in rough order of frequency with fixes, and how to reproduce and verify.
What Android counts as an ANR
Android raises “Application Not Responding” when one of these happens:
- Input dispatching timed out. The app did not respond to a touch or key event within 5 seconds. This is the one players see as the “isn’t responding” dialog.
- Broadcast of intent. A
BroadcastReceiverdid not finish in time (10 seconds while the app has an activity in the foreground). - Executing service. A service did not finish
onCreateoronStartCommandwithin a few seconds, or was started withstartForegroundServiceand did not callstartForegroundwithin 5 seconds. - JobScheduler. A
JobServicedid not return fromonStartJoboronStopJobin time.
Google Play only counts the first kind as user-perceived. The user-perceived ANR rate is the share of daily active users who hit at least one, and Play’s bad behaviour thresholds are 0.47% across all devices and 8% on any single device model. Above the first, the game is less discoverable everywhere. Above the second, it is less discoverable on that model and the listing can carry a warning. What’s an acceptable ANR rate goes through the numbers, and the general mobile ANR guide covers engines other than Unity.
Unity has two main threads
An ANR trace from a Unity game contains two threads that both sound like “the main thread”:
mainis the Android UI thread. It runs the activity’s lifecycle callbacks (UnityPlayerActivity.onPauseand friends), receives input, and hosts every Java SDK callback and WebView. This is the thread Android times.UnityMainruns Unity’s player loop. All your C# runs here:Update, coroutines,OnApplicationPause.
A two-second stall on UnityMain alone is a frozen frame. The UI thread is still free, so it is a hitch, not an ANR. It becomes an ANR when the UI thread has to wait for Unity:
- Pause. When Android calls
onPause, the activity tells the Unity thread to pause and waits for it. Unity first runs everyOnApplicationPausehandler, then stops audio, rendering and the loop. The Java side waits up to 4 seconds on a semaphore. If the next input event then goes unanswered past 5 seconds, that is your ANR. - Resume, focus and surface changes. Coming back to the foreground, a focus change, a rotation or a multi-window resize use the same kind of handshake.
- Java calling into C#.
UnitySendMessagefrom the UI thread takes a native lock. If the Unity thread is busy, the UI thread waits. - Quit. Tearing the player down is a wait as well.
The other family needs no help from Unity: a Java SDK doing disk, network, WebView or cross-process work directly on the UI thread.
Where to get evidence
Play Console. Android vitals > Crashes and ANRs groups ANRs into clusters with the ANR type and the stacks. Filter by app version, Android version and device. Upload native debug symbols with each release (in Unity 2022.3 the Build Settings option is Create symbols.zip), or the libil2cpp.so frames stay as addresses.
logcat. On a device you can reproduce on:
adb logcat -s ActivityManager:E
E ActivityManager: ANR in com.example.mygame (com.example.mygame/com.unity3d.player.UnityPlayerActivity)
E ActivityManager: PID: 12345
E ActivityManager: Reason: Input dispatching timed out (... is not responding. Waited 5001ms for MotionEvent)
The text in the parentheses varies by Android version. See reading Unity Android logs with logcat for filtering.
The trace file. Android writes every thread’s stack to /data/anr/ at the moment of the ANR. That folder is not readable on a retail device, so capture a bug report instead: adb bugreport saves a zip, and the traces are inside it under FS/data/anr/.
ApplicationExitInfo. On Android 11 and later the OS remembers why your process last died, including ANRs and their traces. Unity 6 exposes it directly. On older Unity versions you need a small Java plug-in for the same call.
// Unity 6. Run at start-up to learn how the previous run ended.
#if UNITY_ANDROID && !UNITY_EDITOR
var exits = UnityEngine.Android.ApplicationExitInfoProvider.GetHistoricalProcessExitInfo(null, 0, 5);
foreach (var exit in exits)
{
if (exit.reason == UnityEngine.Android.ExitReason.ANR)
Debug.Log("Previous run ended in an ANR: " + exit.description + "\n" + exit.traceAsString);
}
#endif
How to read the two stacks
Start with main. This is the classic pause ANR, trimmed:
"main" prio=5 tid=1 TimedWaiting
at jdk.internal.misc.Unsafe.park(Native method)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234)
at java.util.concurrent.Semaphore.tryAcquire(Semaphore.java:415)
at com.unity3d.player.UnityPlayer.pauseUnity(UnityPlayer.java)
at com.unity3d.player.UnityPlayer.pause(UnityPlayer.java)
at com.unity3d.player.UnityPlayerActivity.onPause(UnityPlayerActivity.java)
at android.app.Activity.performPause(Activity.java)
The UI thread is waiting, not working. The cause is in the same file under "UnityMain". Its frames are native. With symbols, IL2CPP names look like SaveManager_OnApplicationPause_m... in libil2cpp.so, which maps straight back to a C# method. Frames in libunity.so are engine code: loading, shader work, garbage collection.
Top of the main stack | What it means | Look next at |
|---|---|---|
UnityPlayer.pauseUnity, Semaphore.tryAcquire | Unity did not finish pausing | UnityMain; your pause and focus handlers |
UnityPlayer.nativeUnitySendMessage, MutexLockWithTimeout | A Java plug-in is calling into a busy Unity thread | UnityMain; which SDK sends the message |
libmonochrome.so, org.chromium..., android.webkit | A WebView is working on the UI thread | Ad and consent SDKs |
android.os.BinderProxy.transact | Waiting on another process (Play services, install referrer) | The SDK frames just below it |
android.app.QueuedWork.waitToFinish | Android is flushing pending SharedPreferences writes before pause or stop | PlayerPrefs volume; SDK settings writes |
android.os.MessageQueue.nativePollOnce | The main thread is idle: the trace came late, or this is not an input ANR | The ANR type; CPU load; other threads |
The common causes, with fixes
Heavy work in OnApplicationPause and OnApplicationFocus
The most common Unity-specific ANR. The player presses Home, and the game serialises a save, flushes analytics and writes PlayerPrefs while Android waits.
// Risky: all of this runs while the UI thread waits for Unity to pause
void OnApplicationPause(bool paused)
{
if (!paused) return;
File.WriteAllText(savePath, JsonUtility.ToJson(BuildSaveData()));
analytics.FlushAndWait();
PlayerPrefs.Save();
}
// Better: snapshot on the Unity thread, write on a worker, never wait for it
string savePath; // Application.persistentDataPath is main-thread only, so cache it
void Awake() => savePath = Path.Combine(Application.persistentDataPath, "save.json");
void OnApplicationPause(bool paused)
{
if (!paused) return;
string json = JsonUtility.ToJson(saveData);
Task.Run(() => File.WriteAllText(savePath, json));
}
Save at checkpoints during play as well, so the pause handler has little left to do and little is lost if the process is killed in the background.
Synchronous scene and asset loading
SceneManager.LoadScene, Resources.Load on large assets and Addressables’ WaitForCompletion() hold UnityMain for the whole load. On a slow phone that is several seconds, and a player who switches apps during it turns the stall into an ANR. Use LoadSceneAsync, Resources.LoadAsync and awaited Addressables handles behind a loading screen, and keep the first scene tiny. More in slow first scene load from synchronous asset loads.
Shader compilation and first-frame hitches
The first draw with a shader variant compiles it, and a new scene can need hundreds. Warm a ShaderVariantCollection a few variants per frame during loading:
IEnumerator WarmShaders(ShaderVariantCollection variants)
{
while (!variants.WarmUpProgressively(8))
yield return null;
}
Unity’s documentation notes that on Vulkan the driver may still do work at first draw, so measure on a device.
PlayerPrefs.Save and synchronous file IO
On Android, PlayerPrefs is a SharedPreferences XML file. Megabytes of JSON stored in it make every save slow, and pending writes are flushed when the activity pauses. Keep PlayerPrefs for small settings, put save data in your own file, and write that file from a worker thread.
Blocking on the network or on Tasks
task.Result and task.Wait() on the Unity thread deadlock when the task’s continuation needs that same thread, which is the default for await in Unity. The freeze never ends, and the next touch produces the ANR. The same goes for while (!request.isDone) { } and blocking WebClient calls. Use await or a coroutine all the way up. See async/await freezing the main thread.
Third-party SDKs on the UI thread
Ad SDKs create WebViews, consent dialogs load web content, and attribution SDKs make binder calls, all on main. Initialise SDKs after the first interactive frame and one at a time, not all in the first Awake. Keep them updated: Google Mobile Ads, for example, moves initialisation and ad loading to background threads by default from Unity plug-in 7.2.0, unless the two “Disable” optimisation boxes under Assets > Google Mobile Ads > Settings are ticked. If a cluster points into WebView code, log each ad show and close so you can tie it to a network, and consider pausing that network.
Plug-ins that queue UnitySendMessage calls while the game is in the background deliver them all on resume, on top of your own resume work. Send only the latest state.
GC spikes and low-memory devices
A full collection on a large managed heap can take long enough to matter on a 3 GB phone that is also swapping. Enable Use incremental GC under Player Settings > Other Settings > Configuration, cut per-frame allocations, and release caches in Application.lowMemory. If ANRs cluster on low-RAM models, treat it as a memory problem first.
Application.Quit handling
Quitting runs OnApplicationQuit, OnDisable and OnDestroy across the scene while the activity waits. Keep those handlers free of saves and network calls. If your quit button only mirrors the system Back button, calling the activity’s moveTaskToBack(true) sends the game to the background without tearing it down.
Long native plug-in calls through JNI
AndroidJavaObject.Call blocks UnityMain until the Java method returns. If that method hops to the UI thread and waits there, while the UI thread is waiting for Unity to pause, neither moves. Make plug-in calls asynchronous with a callback through AndroidJavaProxy, and never block on the UI thread from Unity.
How to reproduce one
- Use the slowest device you have. ANRs that take 6 seconds there take 1 on a flagship and never show.
- Interrupt the game at its worst moments: press Home, lock the screen, rotate, or open the recents view during loading, saving, and while an ad is opening. Then come back.
- Exaggerate a suspect. In a development build, put
Thread.Sleep(6000)in the handler you suspect and trigger it. If the trace matches the cluster in vitals, you have the mechanism. - Catch Java SDKs doing IO on the UI thread with StrictMode. It has to be set on that thread:
#if UNITY_ANDROID && !UNITY_EDITOR && DEVELOPMENT_BUILD
using (var player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (var activity = player.GetStatic<AndroidJavaObject>("currentActivity"))
{
activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
{
using (var builder = new AndroidJavaObject("android.os.StrictMode$ThreadPolicy$Builder"))
using (var policy = builder.Call<AndroidJavaObject>("detectAll")
.Call<AndroidJavaObject>("penaltyLog")
.Call<AndroidJavaObject>("build"))
using (var strictMode = new AndroidJavaClass("android.os.StrictMode"))
strictMode.CallStatic("setThreadPolicy", policy);
}));
}
#endif
Violations appear in logcat under the StrictMode tag with the offending stack. It watches the UI thread only, not your C#.
How to confirm the fix in vitals
Ship the fix as a staged rollout and compare like with like: the user-perceived ANR rate for the new version code against the previous one, in Android vitals filtered by version. The cluster you targeted should shrink in that version while others stay put. Give it several days, since the rate is per daily user and small rollouts are noisy. Check the device breakdown too, because the 8% threshold applies per model, and one cheap popular phone can stay over it after the overall rate has dropped.
What Bugnet shows around an ANR
Bugnet’s Unity SDK does not detect ANRs. During one the process is frozen, so no C# runs, and when the player taps “Close app” the process is killed with no chance to send anything. Can crash reporting catch ANRs? explains why that holds for in-process tools generally. Use Android vitals for the count and the traces.
What the Unity SDK gives you is context: errors logged before the freeze, such as a failed save or a timed-out request, with their stack and recent log lines, and the player’s own report (“froze when I switched apps”) with OS version, CPU, RAM and game version. A killed session never reports its end, so ANRs are invisible to Bugnet’s crash-free session rate. To count them, keep a small flag that is set while the game is in the foreground and cleared in OnApplicationPause. If it is still set at launch, call Debug.LogError with a fixed first line, and the SDK files and groups it. On Unity 6, append the ApplicationExitInfo reason and trace.
Related guides
- How to Fix ANR (Application Not Responding) in a Mobile Game
- What’s an Acceptable ANR Rate on Android?
- Can Crash Reporting Catch ANRs?
- How to Read Unity Android Crash Logs with Logcat
- Fix: Unity Async Await Freezing or Blocking the Main Thread
Frequently asked questions
What causes ANRs in Unity Android games?
Most come from the Android main thread waiting on the Unity thread, typically while the game pauses and OnApplicationPause handlers save data or flush analytics. The rest come from SDKs doing WebView, disk or cross-process work on the main thread, synchronous loading, blocked Tasks and deadlocks between the two threads.
What is the difference between the main thread and UnityMain?
The main thread is the Android UI thread that receives input and lifecycle events, and it is the one Android times for ANRs. UnityMain is the thread that runs Unity’s player loop and all your C# scripts. An ANR usually shows main waiting for UnityMain.
What ANR rate does Google Play allow?
Play’s bad behaviour thresholds for user-perceived ANR rate are 0.47 percent of daily active users across all devices and 8 percent on a single device model. Exceeding them reduces the game’s discoverability, and the per-device case can add a warning to the store listing.
How do I get an ANR stack trace from a Unity game?
Play Console shows grouped traces under Android vitals, Crashes and ANRs. On a test device, run adb bugreport and open the files under FS/data/anr in the zip. On Unity 6 and Android 11 or later, ApplicationExitInfo returns the previous run’s ANR trace in code.
Why does my Unity game ANR when the player presses Home?
Pressing Home pauses the activity. The Android main thread tells Unity to pause and waits for it, and Unity first runs every OnApplicationPause handler. If those handlers write large saves or wait on the network, the main thread stays blocked and the next input times out.
In a Unity ANR the main thread stack shows you who is waiting, and the UnityMain stack shows you why. Read both, then make OnApplicationPause do almost nothing.