Runtime exceptions
Coroutine couldn't be started because the game object 'X' is inactive!
The exact message
Coroutine couldn't be started because the game object 'X' is inactive!Variants of this message
- Coroutine couldn't be started because the game object is inactive
- Coroutine couldn't be started because the the game object is inactive!
- Coroutine couldn't be started because the game object 'Scene Loader' is inactive
What it means
StartCoroutine was called on a MonoBehaviour whose GameObject is inactive. Coroutines are driven by the object that owns them, so an inactive object has nothing to advance them and Unity refuses to start one rather than creating a coroutine that would never run. Note that the message quotes the object's name, which is the quickest way to find out which one it is.
Causes and fixes
Ranked by how often they actually occur, most common first.
The object was deactivated before the coroutine was started
A common sequence is to hide something with SetActive(false) and then start a coroutine on it to handle a fade, a delay or a cleanup step. By that point the object cannot run anything. The same happens when a coroutine is started on a UI panel that begins the scene deactivated.
The fix: Start the coroutine before deactivating, or run it on an object that stays active. A manager that is always enabled is the usual home for work that has to outlive the object it concerns.
Order matters: the coroutine must be started while the object can still run it.
using System.Collections; using UnityEngine; public class Panel : MonoBehaviour { // Wrong: nothing can advance the coroutine once the object is inactive. public void HideBroken() { gameObject.SetActive(false); StartCoroutine(FadeOut()); } // Right: fade first, then deactivate at the end of the routine. public void Hide() { StartCoroutine(FadeThenHide()); } private IEnumerator FadeThenHide() { yield return FadeOut(); gameObject.SetActive(false); } private IEnumerator FadeOut() { yield return new WaitForSeconds(0.25f); } }Source: Unity Discussions: coroutine couldn't be started because the game object is inactive
A parent is inactive, so the object is inactive too
An object is only active in the scene if it and every ancestor above it are active. Selecting the object and seeing its own checkbox ticked proves nothing if a parent higher up is disabled. This is the version that reads as a contradiction, because the object plainly looks enabled in the Inspector.
The fix: Check activeInHierarchy rather than activeSelf. activeSelf reports only the object's own checkbox; activeInHierarchy accounts for every parent and is what determines whether a coroutine can run.
The two properties answer different questions, and only one of them matters here.
using UnityEngine; public class Diagnostics : MonoBehaviour { void Start() { // True if this object's own checkbox is ticked. Debug.Log($"activeSelf: {gameObject.activeSelf}"); // True only if this object and every parent are active. // This is the one StartCoroutine cares about. Debug.Log($"activeInHierarchy: {gameObject.activeInHierarchy}"); if (!gameObject.activeInHierarchy) { Debug.LogWarning($"{name} cannot run coroutines: a parent is inactive.", this); } } }Source: Unity Scripting API: GameObject.activeInHierarchy, Unity Discussions: error appears when the GameObject looks active
A scene transition deactivated the object mid-sequence
Loading a scene tears down the previous one, and objects can be deactivated or destroyed between a coroutine being requested and it actually starting. A loading screen that starts a coroutine on an object belonging to the outgoing scene is the classic case, which is why this error clusters around scene transitions.
The fix: Run transition work on an object that survives the load, marked with DontDestroyOnLoad, or on a manager belonging to the incoming scene. Re-check the object is still active after any await or yield that spans a load.
Source: Unity Scripting API: Object.DontDestroyOnLoad, GameDev.tv: error when transitioning to a new scene
The object was deactivated between the check and the call
Checking activeInHierarchy and then calling StartCoroutine leaves a window in which something else can deactivate the object, usually another script responding to the same event. The check passes, the call fails, and the code looks correct on inspection. This is rare but genuinely happens during rapid transitions.
The fix: Move the work to an object whose lifetime you control rather than defending the call site. Where that is not practical, wrapping the call and tolerating the failure is honest, but it is a symptom of ownership being in the wrong place.
How to prevent it
Put long-running or transition work on a persistent manager rather than on the objects it affects. An object that hides, dies or unloads partway through is the wrong owner for a routine that has to finish.
Order deactivation last. Anything that needs to run before an object disappears must be started while it is still active, and the deactivation belongs at the end of that routine rather than before it.
Use activeInHierarchy when you need to know whether something can actually run. activeSelf answers a different question and is the reason this error so often looks impossible.
Consider async and await with a CancellationToken where work must survive an object being disabled. Unlike coroutines, that work is not owned by a MonoBehaviour, which is sometimes exactly what you want and sometimes a leak waiting to happen.
Unity version differences
Behaviour is unchanged across supported versions. Older Unity releases emitted the message with a duplicated word, as "because the the game object is inactive", which is worth knowing when searching for it.
Related errors
- MissingReferenceExceptionWhy Unity says an object has been destroyed but you are still accessing it, how destroyed objects differ from null, and the four causes worth checking.
- NullReferenceExceptionWhy Unity throws NullReferenceException, how to read the stack trace to find the exact line, and the five causes that account for nearly all of them.
- Scene not in build settingsWhy Unity says a scene has not been added to the build settings, including the case where the scene is already in the list. Six ranked causes with fixes.
Related tools
Sources
- Unity Scripting API: MonoBehaviour.StartCoroutine
- Unity Scripting API: GameObject.activeInHierarchy
- Unity Discussions: coroutine couldn't be started because the game object is inactive
- Unity Discussions: error appears when the GameObject looks active
- Unity Scripting API: Object.DontDestroyOnLoad
- GameDev.tv: error when transitioning to a new scene