본문으로 건너뛰기
Skillpedia
일반 코딩6.6k · #13850

unity-scriptableobjects

하는 일

이 스킬은 Unity 설정과 공유 데이터를 프로젝트 에셋 파일에 보관하고, 게임 시스템을 강하게 묶지 않고 연결하는 방법을 설명합니다. 더 깔끔한 Unity 프로젝트를 원하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓디자이너가 능력치나 레벨 설정을 Unity 에셋 파일로 편집하기를 원할 때.
  • ✓많은 스크립트가 의존하는 싱글턴이나 매니저를 교체해야 할 때.
  • ✓서로 관련 없는 Unity 시스템이 하나의 값을 공유하거나 서로 이벤트를 보내야 할 때.

스킬 링크

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-scriptableobjects/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-scriptableobjects/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“무기 피해량과 발사 속도를 Unity 에셋 파일에 저장해서, 코드를 건드리지 않고 바꿀 수 있게 해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

데이터 클래스를 에셋으로 만드는 방법, 스크립트에서 이를 참조하는 방법, 공유 채널로 이벤트를 전달해 시스템을 느슨하게 연결하는 방법을 설명합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Unity ScriptableObject Architecture

Use ScriptableObject assets to store shared data and decouple systems in Unity 6.3 LTS — configuration, event channels, and registries that live as project assets instead of being hard-wired into scenes or singletons. Targets Unity 6.3 LTS (6000.3).

When to use

  • Use when you need designer-editable config (weapon stats, level data), to share one value between unrelated systems, to decouple senders from listeners via event channels, or to build a runtime registry of active objects — without a static/singleton manager.
  • Use when the project has *.asset data files backed by : ScriptableObject classes.

When not to use: per-instance runtime state that differs per GameObject (that belongs on a MonoBehaviour) — a ScriptableObject asset is shared by everyone who references it. Saving player progress to disk → save-systems. Plain DTOs that never need to be an asset can just be [System.Serializable] classes.

Core workflow

  1. Define the class deriving from ScriptableObject and tag it with [CreateAssetMenu] so designers can create instances from the Assets menu.
  2. Create one or more .asset instances in the Project window; each is a shared, named piece of data referenced by [SerializeField] fields.
  3. Reference, don't copy. MonoBehaviours hold a reference to the asset; they all see the same data, so changing the asset changes every consumer.
  4. For decoupling, model signals and shared variables as ScriptableObjects: a "FloatVariable" the HUD reads and the player writes; an "event channel" the player raises and many systems listen to. Neither side references the other.
  5. Reset runtime mutations in OnEnable if the asset is mutated during play, because edits made in the Editor at runtime persist on the asset (a frequent source of "my values changed after I played").
  6. Verify by inspecting the asset values during Play mode and confirming consumers react.

Patterns

1. Config/data asset

using UnityEngine;

[CreateAssetMenu(fileName = "WeaponData", menuName = "Game/Weapon Data", order = 0)]
public class WeaponData : ScriptableObject
{
    public string displayName = "Pistol";
    public int    damage = 10;
    public float  fireRate = 0.25f;
    public GameObject projectilePrefab;
}
public class Weapon : MonoBehaviour
{
    [SerializeField] private WeaponData data;   // assign the shared asset in the Inspector
    private void Fire() => Debug.Log($"{data.displayName} for {data.damage}");
}

2. Shared runtime variable (decouples producer from consumer)

[CreateAssetMenu(menuName = "Game/Float Variable")]
public class FloatVariable : ScriptableObject
{
    [SerializeField] private float initialValue;
    [System.NonSerialized] public float runtimeValue;   // not saved to the asset

    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.

3. Creating an instance at runtime (not an asset on disk)

// For transient SO data you build in code (e.g. a generated config).
var temp = ScriptableObject.CreateInstance<WeaponData>();
temp.damage = 25;
// ...use temp...  Destroy(temp);   // clean up runtime-created instances

Pitfalls

  • Editing an SO at runtime persists in the Editor — values you change during Play stay changed on the asset after you stop. Keep mutable runtime state in [NonSerialized] fields reset in OnEnable, or it will surprise you. (In a build, asset edits do not persist across launches.)
  • 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
자주 묻는 질문

ScriptableObject는 일반 컴포넌트와 같나요?

아니요. ScriptableObject는 공유 프로젝트 에셋이고, 컴포넌트는 씬의 한 객체에 속합니다.

플레이어 진행 상황을 여기에 저장할 수 있나요?

주 저장 수단으로는 안 됩니다. 디스크에 진행 상황을 저장하는 방법은 별도의 저장 스킬에서 다룹니다.

Unity 6에서도 작동하나요?

네. 이 스킬은 Unity 6.3 LTS를 대상으로 합니다.

상세 정보

작성자의 원본 설명

Architect Unity 6.3 LTS data and decoupling with ScriptableObjects: config/data assets, shared runtime variables, event channels, and runtime sets/registries. Use when designing data-driven systems, replacing singletons/managers, creating .asset data with CreateAssetMenu, or when the user mentions ScriptableObject, SO architecture, or data assets.

repo: gamedev-skills/awesome-gamedev-agent-skills

인기도

GitHub 스타
6.6k
순위
#13850
라이선스
Apache-2.0
업데이트
2026. 10. 28.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬