Skip to content

77 game-dev skills for AI coding agents — Godot, Unity, Unreal, Phaser, PixiJS, three.js, Bevy, pygame, LÖVE, Roblox. Portable SKILL.md Agent Skills (the format Anthropic launched as Claude Skills), with a router that loads the right skill for your engine and task. Runs in Claude Code, Cursor, Kiro, Codex, Copilot, Gemini CLI and more.

fix(unity): ScriptableObject reset works with domain reload disabled

Kiro Crew89229d9cfe21
diff --git a/skills/unity/unity-scriptableobjects/SKILL.md b/skills/unity/unity-scriptableobjects/SKILL.md
index e02987e..382c99d 100644
--- a/skills/unity/unity-scriptableobjects/SKILL.md
+++ b/skills/unity/unity-scriptableobjects/SKILL.md
@@ -75,7 +75,24 @@ public class FloatVariable : ScriptableObject
[SerializeField] private float initialValue;
[System.NonSerialized] public float runtimeValue; // not saved to the asset
- private void OnEnable() => runtimeValue = initialValue; // reset each play session
+ private void OnEnable()
+ {
+ runtimeValue = initialValue; // reset when the asset loads
+#if UNITY_EDITOR
+ // With Reload Domain off, OnEnable does not run again on Play, so also reset there.
+ UnityEditor.EditorApplication.playModeStateChanged -= ResetOnPlay;
+ UnityEditor.EditorApplication.playModeStateChanged += ResetOnPlay;
+#endif
+ }
+
+#if UNITY_EDITOR
+ private void OnDisable() => UnityEditor.EditorApplication.playModeStateChanged -= ResetOnPlay;
+
+ private void ResetOnPlay(UnityEditor.PlayModeStateChange change)
+ {
+ if (change == UnityEditor.PlayModeStateChange.ExitingEditMode) runtimeValue = initialValue;
+ }
+#endif
}
// Player writes playerHealth.runtimeValue; the HUD reads it — neither references the other.
```
@@ -98,8 +115,9 @@ temp.damage = 25;
- **Disabled Domain Reload skips your `OnEnable` reset** — with **Enter Play Mode Options**
enabled and **Reload Domain** off (a Unity 6.3 LTS fast-iteration setting), already-loaded SOs are
_not_ re-created when you press Play, so `OnEnable` never fires and `runtimeValue` keeps its
- value from the previous session. Reset explicitly from an `ISerializationCallbackReceiver` or
- a scene-load hook instead of relying on `OnEnable` alone.
+ value from the previous session (non-serialized fields keep their Play-mode values). Also
+ reset on `EditorApplication.playModeStateChanged` (pattern 2), or from a static
+ `[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]` method.
- **Expecting per-object state** — every reference points to the _same_ asset. If two enemies
need different current HP, store HP on the MonoBehaviour, not the shared SO.
- **No frame lifecycle** — ScriptableObjects have `OnEnable`/`OnDisable`/`OnDestroy` but no
@@ -115,6 +133,7 @@ temp.damage = 25;
**runtime sets/registries** (a shared list of active enemies), read
`references/event-channels.md`.
- Primary docs: Unity Manual "ScriptableObject" (`/Manual/class-ScriptableObject.html`) and
+ "Enter Play mode with domain reload disabled" (`/Manual/domain-reloading.html`), plus
`ScriptReference/ScriptableObject`, `ScriptReference/CreateAssetMenuAttribute`.
## Related skills
diff --git a/skills/unity/unity-scriptableobjects/references/event-channels.md b/skills/unity/unity-scriptableobjects/references/event-channels.md
index 71f431b..4b44d9d 100644
--- a/skills/unity/unity-scriptableobjects/references/event-channels.md
+++ b/skills/unity/unity-scriptableobjects/references/event-channels.md
@@ -68,7 +68,7 @@ generic `GameEvent<T>` because Unity cannot create assets for open generic types
## Runtime set / registry (a shared, live collection)
-Instead of `FindObjectsOfType` every frame, objects add themselves to a shared set on enable
+Instead of `FindObjectsByType` (or the obsolete `FindObjectsOfType`) every frame, objects add themselves to a shared set on enable
and remove on disable. Systems (AI targeting, minimap) read the set.
```csharp
@@ -97,7 +97,8 @@ what is alive.
- `List` fields on a ScriptableObject are populated at runtime and **persist in the Editor**
between play sessions unless cleared. Clear runtime sets in `OnEnable` (or `OnDisable`) so a
- stale entry from the last session doesn't linger.
+ stale entry from the last session doesn't linger; with Reload Domain off those callbacks do
+ not run between sessions, so clear on a Play-mode change as in the main skill's pattern 2.
- Always `Unregister`/`Remove` in `OnDisable`; objects destroyed without cleanup leave null
entries that crash listeners.
- Event channels invoke synchronously on the raiser's thread/frame — a heavy listener stalls