unity-scriptableobjects
БесплатноБез исполняемых скриптовНе проверенUnity 6.3 LTS data and decoupling with ScriptableObjects: CreateAssetMenu config assets, shared runtime variables, event channels and .asset files made from…
от gamedev-skills★ 12 656 звёзд на GitHubОб этом скилле
Unity ScriptableObject Architecture
Use ScriptableObject assets in Unity 6.3 LTS (6000.3) for shared data and for decoupling
systems: configuration, event channels and registries that live as project assets instead of
scene singletons. An SO asset is a YAML file you can read and check without the Editor.
When to use
- Designer-editable config (weapon stats, level data), one value shared by unrelated systems, senders and listeners that should not reference each other, a live registry of active objects without scene scans.
- The project has
*.assetfiles backed by: ScriptableObjectclasses.
When not to use: state that differs per GameObject belongs on a MonoBehaviour, since an SO
asset is shared by everyone who references it; saving progress → save-systems; plain data
that never needs to be an asset can be a [System.Serializable] class.
Workflow
- Define the class deriving from
ScriptableObject, in a file with the same name, with[CreateAssetMenu]so designers can create instances. - Create the assets. Designers use the Assets > Create menu. From code, use an editor
script (pattern 3) so Unity writes the
.assetand its.metawith a valid GUID. Do not hand-write a new.assetfile: them_ScriptGUID must match the script's.meta. - Reference, do not copy. MonoBehaviours hold a
[SerializeField]reference; every consumer sees the same data. - Keep mutable runtime state out of serialized fields (
[System.NonSerialized]) and reset it when Play mode starts (pattern 2), because Play-mode edits to an asset persist in the Editor. - Make sure builds include the asset. Only assets referenced from a scene in the build,
from another included asset, from a
Resourcesfolder or from Addressables ship in the player. - Verify with the checks below.
Patterns
1. Config asset
using UnityEngine;
[CreateAssetMenu(fileName = "WeaponData", menuName = "Game/Weapon Data")]
public class WeaponData : ScriptableObject
{
public string displayName = "Pistol";
public int damage = 10;
public float fireRate = 0.25f;
public GameObject projectilePrefab;
}
2. Shared runtime variable that resets on Play
using UnityEngine;
[CreateAssetMenu(menuName = "Game/Float Variable")]
public class FloatVariable : ScriptableObject
{
[SerializeField] private float initialValue;
[System.NonSerialized] public float runtimeValue; // never saved to the asset
private void OnEnable()
{
runtimeValue = initialValue;
#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
}
3. Create assets from editor code
Put this in an Editor folder. Run it from the menu, from the Unity CLI with
unity command script eval --code 'WeaponAssets.CreateDefaults();', or in batch mode with
-executeMethod WeaponAssets.CreateDefaults.
using UnityEditor;
using UnityEngine;
public static class WeaponAssets
{
[MenuItem("Tools/Create Default Weapons")]
public static void CreateDefaults()
{
if (!AssetDatabase.IsValidFolder("Assets/Data"))
AssetDatabase.CreateFolder("Assets", "Data");
var pistol = ScriptableObject.CreateInstance<WeaponData>();
pistol.displayName = "Pistol";
pistol.damage = 10;
AssetDatabase.CreateAsset(pistol, "Assets/Data/Pistol.asset"); // writes .asset and .meta
AssetDatabase.SaveAssets();
}
}
To change an existing asset from editor code, load it with
AssetDatabase.LoadAssetAtPath<WeaponData>(path), set the fields, call
EditorUtility.SetDirty(asset) and then AssetDatabase.SaveAssets(); without SetDirty the
change is lost on the next reload.
Verify
- No Editor needed: an SO asset is YAML. Each
.assethas aMonoBehaviour:document withm_Script: {fileID: 11500000, guid: ..., type: 3},m_Name, and one line per serialized field (damage: 10). Grep the values, and rununity-csharp-scripting'scheck_unity_project.pyto confirm everym_ScriptGUID resolves to a script. - Unity CLI with a ready Editor: read the loaded value back:
unity command script eval --code 'return AssetDatabase.LoadAssetAtPath<WeaponData>("Assets/Data/Pistol.asset").damage;' - Tests: an EditMode test can load the asset with
AssetDatabase.LoadAssetAtPathand assert its values, or exercise an event channel withScriptableObject.CreateInstance(setup
Установить unity-scriptableobjects в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл unity-scriptableobjects?
Unity 6.3 LTS data and decoupling with ScriptableObjects: CreateAssetMenu config assets, shared runtime variables, event channels and .asset files made from code. Use for replacing singletons, data-driven items or cards, or values that persist after leaving Play mode. Not for saving progress (`save-systems`) or Godot Resources (`godot-resources`).
Как установить скилл unity-scriptableobjects?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unity-scriptableobjects запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic