unity-lifecycle

Manage Unity MonoBehaviour lifecycle callbacks and execution order patterns.

24|5|Updated Mar 10, 2026
One-click install
npx skills add https://github.com/Nice-Wolf-Studio/unity-claude-skills --skill unity-lifecycle
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-lifecycle
Source: https://github.com/Nice-Wolf-Studio/unity-claude-skills/tree/main/skills/unity-lifecycle
Command: npx skills add https://github.com/Nice-Wolf-Studio/unity-claude-skills --skill unity-lifecycle

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers avoid common pitfalls related to Unity's script execution order, initialization timing, and object destruction, preventing bugs like MissingReferenceException and ensuring predictable behavior in builds.

Core Features & Use Cases

  • Lifecycle Correctness: Understand and apply patterns for Awake, Start, OnEnable, OnDisable, OnDestroy, and OnApplicationQuit.
  • Editor vs. Runtime: Differentiate and correctly use editor-only callbacks like OnValidate and [ExecuteAlways].
  • Async Safety: Safely handle asynchronous operations within the Unity lifecycle using destroyCancellationToken.
  • Use Case: Prevent a common bug where a script tries to access a GameManager instance that hasn't been initialized yet by correctly ordering script execution.

Quick Start

Use the unity-lifecycle skill to understand the correct pattern for subscribing to events using OnEnable and OnDisable.

Frequently Asked Questions about unity-lifecycle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Unity script execution order when a MonoBehaviour tries to access an uninitialized GameManager?

Unity script execution order issues are resolved by correctly applying MonoBehaviour lifecycle callbacks like Awake and Start, ensuring dependencies such as a GameManager instance are fully initialized before other scripts attempt to access them.

Why does my Unity script throw a MissingReferenceException during object destruction?

Unity MissingReferenceException during destruction occurs when scripts access destroyed objects, which you can prevent by applying correct lifecycle management patterns using OnDisable and OnDestroy to safely unsubscribe from events and release references.

How do I safely handle async methods within the Unity lifecycle?

To safely handle async methods within the Unity lifecycle, use destroyCancellationToken to automatically cancel asynchronous operations when the associated GameObject is destroyed, preventing memory leaks and missing reference errors.

What is the difference between editor and runtime lifecycle callbacks in Unity?

Editor and runtime lifecycle differences in Unity involve using editor-only callbacks like OnValidate and attributes such as [ExecuteAlways] to ensure scripts execute correctly in edit mode versus actual runtime builds.

When should I use Awake vs OnEnable vs Start for Unity initialization?

Awake, OnEnable, and Start in Unity serve distinct initialization roles: Awake sets up component references, OnEnable handles event subscriptions, and Start performs logic that depends on other scripts being fully initialized.

Can I use RuntimeInitializeOnLoadMethod to control Unity script startup timing?

Yes, you can use the [RuntimeInitializeOnLoadMethod] attribute in Unity to execute static initialization logic immediately after the runtime loads, allowing you to set up core systems before any MonoBehaviour lifecycle callbacks run.