Unity Lifecycle
Unsigned, install at your own risk
UnverifiedThis skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.
Install this skill
No account required. Pick your tool, then copy.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install multi-language-standards-unity-lifecycleWhat this does: Protect Unity runtime behavior across callbacks, subscriptions, destroyed objects, and Play Mode sessions. Use for Unity lifecycle, domain reload, callback order, event cleanup, main-thread access, or Play Mode lifetime questions. (triggers: Unity lifecycle, Unity domain reload, Unity callback order, Unity destroyed object, Unity main thread, Unity subscription lifetime)
Manual setup by platform
Claude Code
~/.claude/skills/multi-language-standards-unity-lifecycle/SKILL.md
Instructions
Unity Lifecycle and Session State
Priority: P1 (HIGH)
Own the lifetime of Unity static fields and event handlers; do not depend on domain reload.
Callback Order
- Creation:
Awakeonce per object, thenOnEnable;Startbefore the firstUpdate. - Frame:
FixedUpdatefor physics,Updatefor frame logic,LateUpdateafterUpdate. - Teardown:
OnDisablebeforeOnDestroy; scene unload and application quit also destroy objects. - Ordering: Use Script Execution Order only when cross-object order is a real contract; otherwise make each object self-contained.
Subscription Lifetime
- Subscribe in
OnEnable; unsubscribe the same handler inOnDisable. - Unsubscribe before destroying or pooling the listener; a destroyed listener can remain in a static event.
- With domain reload disabled, static fields and static event subscribers persist between Play Mode sessions. Cleanup must run on exit or the next session accumulates handlers.
- With scene reload disabled, Unity still calls
OnEnable,OnDisable, andOnDestroyfor runtime scripts. Do not assume scene reload is cleaning up for you.
Destroyed-Object Null Semantics
- Unity overloads
==forUnityEngine.Object; a destroyed object can compare equal tonullwhile the managed reference still exists. - Use
if (target == null)for Unity objects. Do not use?.,??,is null, orReferenceEqualsas a substitute for Unity's lifetime check. - A destroyed listener invoked through a static event can still run its managed method. Remove the subscription; do not rely on a null check alone.
Main-Thread Access
- Unity API calls belong on the main thread. Do not touch
Transform,Rigidbody, scenes, or mostUnityEngineobjects from a worker. - Marshal work by queueing a payload and draining it in
Update, or by posting through a main-threadSynchronizationContext. - Keep the worker payload plain data; resolve Unity objects on the main thread.
Disabled Domain Reload
- Reset runtime statics on exit or on entering Play Mode;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]is the runtime hook for enter-time reset. - Do not clear statics between the two sessions of a persistence test; that hides the bug the test is meant to catch.
- Verify with two actual Play Mode sessions in one Editor process, domain reload disabled, and a fixed scene-reload setting.
- Raise one event per session and assert the second-session callback delta is exactly one. Add a missing-cleanup control that produces two callbacks in the second session.
Verification
- Use a Play Mode test or an Editor driver that enters and exits Play Mode twice in one process.
- Record the Editor version, domain/scene reload settings, event count, callback delta per session, and whether any recompile occurred.
- A compile-only or Edit Mode-only result does not prove runtime subscription cleanup.
Anti-Patterns
- No "domain reload will reset it": Static state and handlers persist when domain reload is disabled.
- No
?.on Unity objects: It bypasses Unity's destroyed-object semantics. - No background Unity API: Marshal to the main thread before touching scene objects.
- No single-session proof: A cleanup claim needs a second Play session.
References
- Lifecycle, domain reload, and two-session verification
Security
Reviews (0)
Related skills
Browse all →More from Multi-Language Standards
View source →More Game Dev skills
Browse category →Frequently asked questions about unity-lifecycle
What does the unity-lifecycle skill do?
Protect Unity runtime behavior across callbacks, subscriptions, destroyed objects, and Play Mode sessions. Use for Unity lifecycle, domain reload, callback order, event cleanup, main-thread access, or Play Mode lifetime questions. (triggers: Unity lifecycle, Unity domain reload, Unity callback order, Unity destroyed object, Unity main thread, Unity subscription lifetime) It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the unity-lifecycle skill?
Run `npx @skills-hub-ai/cli install multi-language-standards-unity-lifecycle` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/multi-language-standards-unity-lifecycle/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does unity-lifecycle work with?
unity-lifecycle runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the unity-lifecycle skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use unity-lifecycle after installing it?
In Claude Code, type `/multi-language-standards-unity-lifecycle` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the unity-lifecycle skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.
Badge for your README
Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.
[](https://skills-hub.ai/skills/multi-language-standards-unity-lifecycle)<a href="https://skills-hub.ai/skills/multi-language-standards-unity-lifecycle"><img src="https://skills-hub.ai/api/badges/skill/multi-language-standards-unity-lifecycle" alt="Install on Skills Hub"></a>More options in the badge docs.