Unity Play Mode Exits Immediately - How to Fix (Testing Issues)
Problem: You press Play in the Unity Editor but Play Mode turns off almost right away. The game may not run at all, or it runs for a second and then stops. You cannot test your game normally.
Quick Solution: The most common causes are script compilation errors, exceptions in Awake/Start/OnEnable, or Editor settings that exit Play Mode on recompile. Fix script errors first, then check Console for exceptions and disable "Exit Play Mode on recompile" if needed.
This guide walks you through the main causes and fixes so you can keep Play Mode running and test your game.
Why Play Mode Exits Immediately
Play Mode can stop right away when:
- Scripts have compile errors β Unity may not enter Play Mode properly or may exit as soon as it tries to run code.
- An exception runs in Awake, Start, or OnEnable β If any script throws in these methods, the engine can stop Play Mode or the first frame never finishes.
- Domain Reload exits Play Mode β If "Enter Play Mode Options" is set to reload the domain and a script change triggers a recompile, Play Mode can exit.
- No active scene or empty scene β Sometimes an invalid or empty scene setup causes Play Mode to end quickly.
- Editor or project corruption β Rarely, a bad preference or project state makes Play Mode unstable.
Fixing compile errors and runtime exceptions first usually resolves the issue.
Solution 1: Fix Script Compilation Errors
If there are any errors in the Console (red icons), Unity may not run your scripts correctly and Play Mode can exit or behave oddly.
Step-by-Step Fix
-
Open the Console
- Go to Window > General > Console (or Ctrl+Shift+C / Cmd+Shift+C).
-
Clear and check for errors
- Click Clear to remove old messages.
- Look for compile errors (red). Fix every error before relying on Play Mode.
-
Fix the reported errors
- Click an error to jump to the script and line.
- Fix missing namespaces, typos, missing semicolons, or broken references. Save the script and wait for Unity to recompile.
-
Press Play again
- Once the Console shows zero errors (warnings are OK for this step), press Play. If Play Mode still exits, go to Solution 2.
Verification: The Console has no red errors and Play Mode stays on when you press Play.
Solution 2: Find Exceptions in Awake, Start, or OnEnable
If a script throws an exception during Awake, Start, or OnEnable, Play Mode can stop almost immediately. The exception might appear in the Console only briefly.
Step-by-Step Fix
-
Open the Console and enable Pause on Error (optional)
- In the Console, click the three-dot menu and enable Error Pause (or Pause on Error) if available. That way the Editor pauses when an error is thrown so you can read it.
-
Press Play and watch the Console
- Press Play and look at the Console as soon as it runs. Note any red error messages and the script name and line number.
-
Add temporary debug logs
- In scripts that run early (e.g.
Awake,Start,OnEnable), add a simpleDebug.Log("ScriptName.Awake");at the very top. Run Play again and see which log appears last before Play Mode exits. That narrows down which script is failing.
- In scripts that run early (e.g.
-
Fix the failing script
- Common issues: NullReferenceException (missing reference in the Inspector, or accessing a destroyed object), MissingReferenceException, or calling something that is not ready yet. Add null checks, ensure references are assigned, and avoid depending on other objects that might not be initialized in the same frame.
-
Remove debug logs and test again
- Once the exception is fixed, remove the temporary logs and confirm Play Mode runs.
Verification: No exceptions appear in the Console when entering Play Mode, and Play Mode stays on.
Solution 3: Adjust Enter Play Mode Settings (Domain Reload)
In Unity 2019.3 and later, Enter Play Mode Options can change how often scripts are recompiled and whether the domain reloads. If Play Mode is set to exit when the domain reloads, a recompile during Play can turn it off immediately.
Step-by-Step Fix
-
Open Project Settings
- Go to Edit > Project Settings > Editor.
-
Check Enter Play Mode Options
- Find Enter Play Mode Options (or Enter Play Mode Settings).
- If Reload Domain is enabled and you have Exit Play Mode on script recompile (or similar) behavior, Play Mode can exit when Unity recompiles. Try disabling Reload Domain for testing (optional, can have side effects), or ensure you are not saving/editing scripts while in Play Mode so recompile does not trigger.
-
Simplify for testing
- As a test, you can turn off Reload Domain and Reload Scene to see if Play Mode stays on. If it does, the issue may be tied to domain reload or recompile. Re-enable them later if your project relies on them and fix the underlying script/compile issue instead.
Verification: Play Mode no longer exits right after a recompile, or you have identified that recompile is the trigger and you avoid editing scripts during Play.
Solution 4: Check Scene and Camera
Sometimes an empty scene, missing camera, or broken scene setup can make it look like Play Mode "did nothing" or exited immediately.
Step-by-Step Fix
-
Confirm the scene has content
- Ensure the open scene has at least a Camera (or a camera from a package) and something to run (e.g. a GameObject with a script that runs in Start). If the scene is empty and no script runs, it can look like Play Mode exited right away.
-
Check that the correct scene is active
- In File > Build Settings, the first scene in the list is the one that loads in a build. In the Editor, the scene you have open is the one that runs when you press Play. Make sure that scene is the one you expect.
-
Try a minimal test scene
- Create a new scene, add a Cube and a Main Camera, and add a simple script to the Cube that only does
Debug.Log("Running");inStart. Press Play. If Play Mode stays on here, the issue is likely in your main scene or scripts.
- Create a new scene, add a Cube and a Main Camera, and add a simple script to the Cube that only does
Verification: In a minimal scene, Play Mode runs and stays on; you can then bring that knowledge back to your main scene.
Prevention Tips
- Keep the Console visible while testing and fix compile errors as soon as they appear.
- Avoid throwing in Awake/Start/OnEnable; add null checks and defensive checks so one bad reference does not stop the whole game.
- Do not rely on script execution order for critical setup; use lazy initialization or events so objects are ready when used.
- Use Version Control so you can revert recent script or scene changes if Play Mode suddenly starts exiting.
When to Look Elsewhere
- If Play Mode never starts (Play button does not respond), focus on compile errors and Editor stability (restart Unity, clear Library if needed).
- If Play Mode runs in a new empty project but not in yours, the cause is in your projectβs scripts or scenes; use the logging approach above to find the failing script.
- If the game runs in a build but not in the Editor, the issue is often Editor-only code or different initialization order in the Editor; check
#if UNITY_EDITORand any code that runs only in the Editor.
Related Help
- Unity Console Errors Not Showing - Debug Console Fix β If you cannot see errors when Play Mode exits.
- Unity Editor Freezes / Not Responding - How to Fix β If the Editor hangs instead of exiting Play Mode.
- Unity Project Won't Open / Corrupted - Data Recovery Guide β If the project or Editor is in a bad state.
Bookmark this page for quick reference when Play Mode exits immediately. If you found it useful, share it with other developers who hit the same issue.