unity runtime_error ai_generated true

NullReferenceException in coroutine MoveNext

ID: unity/coroutine-null-reference

Also available as: JSON · Markdown
80%Fix Rate
84%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2022 active

Root Cause

Object destroyed while coroutine is running.

generic

Workarounds

  1. 88% success Check if object is alive before yield: if(this==null) yield break
  2. 90% success Use cancellation tokens or stop coroutine before destroying

Dead Ends

Common approaches that don't work:

  1. Wrap entire coroutine in try-catch 75% fail

    Silences error but coroutine state is broken

  2. Never destroy objects that have coroutines 78% fail

    Memory leaks