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가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
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
*.assetdata files backed by: ScriptableObjectclasses.
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
- Define the class deriving from
ScriptableObjectand tag it with[CreateAssetMenu]so designers can create instances from the Assets menu. - Create one or more
.assetinstances in the Project window; each is a shared, named piece of data referenced by[SerializeField]fields. - Reference, don't copy. MonoBehaviours hold a reference to the asset; they all see the same data, so changing the asset changes every consumer.
- 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.
- Reset runtime mutations in
OnEnableif 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"). - 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 inOnEnable, or it will surprise you. (In a build, asset edits do not persist across launches.) - Disabled Domain Reload skips your
OnEnablereset — 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.
인기도
- GitHub 스타
- 6.6k
- 순위
- #13850
- 라이선스
- Apache-2.0
- 업데이트
- 2026. 10. 28.
댓글
- …
이 저장소의 다른 스킬
router
6.6k에이전트가 엔진과 작업 종류를 파악해, 요청에 맞는 게임 개발 스킬을 골라 주도록 돕습니다.
ai-behavior-trees-utility-ai
6.6k에이전트가 적이나 캐릭터가 우선순위와 점수로 행동을 고르는 행동 트리와 유틸리티 AI 시스템을 만들도록 돕습니다.
audio-design
6.6k에이전트에게 게임 오디오 믹싱을 가르칩니다. 버스, 데시벨 음량, 대사 아래에서의 덕킹, 적응형 음악, 효과음 변주를 다룹니다.
camera-systems
6.6k에이전트가 부드럽게 따라가고, 레벨 안에 머물고, 3D에서 회전하거나 둘러볼 수 있는 게임 카메라를 만들도록 돕습니다.