Skilllibrary unity
Guides Unity C# development — MonoBehaviour lifecycle, component architecture, ScriptableObjects, Addressables, New Input System, Physics, ECS/DOTS, coroutines, UI Toolkit, Assembly Definitions, prefab workflows, and common C# patterns like object pooling and SerializeField. Use when writing, reviewing, or architecting Unity project code.
install
source · Clone the upstream repo
git clone https://github.com/merceralex397-collab/skilllibrary
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/merceralex397-collab/skilllibrary "$T" && mkdir -p ~/.claude/skills && cp -r "$T/13-game-engines-and-creative-tech/unity" ~/.claude/skills/merceralex397-collab-skilllibrary-unity && rm -rf "$T"
manifest:
13-game-engines-and-creative-tech/unity/SKILL.mdsource content
Purpose
Provide concrete C# patterns, API usage, and architectural guidance for Unity projects — covering lifecycle methods, component design, asset management, input handling, physics, UI, and performance optimization.
When to use this skill
- Writing or reviewing MonoBehaviour scripts using lifecycle methods (
,Awake
,Start
,Update
,FixedUpdate
,LateUpdate
)OnDestroy - Designing component architecture with
,GetComponent<T>()
,AddComponent<T>()[RequireComponent] - Creating ScriptableObject data containers, shared configs, or event channels with
[CreateAssetMenu] - Configuring Addressables:
, asset groups, labels, remote catalogsAddressables.LoadAssetAsync<T>() - Setting up New Input System:
,InputAction
component, action maps, runtime rebindingPlayerInput - Physics work: Rigidbody, colliders, triggers, layer masks,
,Physics.Raycast()OnCollisionEnter - ECS/DOTS:
structs,IComponentData
/SystemBase
,ISystem
, Burst-compiled jobsEntityManager - UI Toolkit: USS styling, UXML layout,
hierarchy, data binding withVisualElementSerializedObject - Project structure: Assembly Definitions (
), platform defines (.asmdef
), prefab workflows#if UNITY_ANDROID
Do not use this skill when
- The project uses Unreal Engine — use
orunreal-engineue5-blueprint - The task is specifically about ScriptableObject event architecture — use
unity-scriptableobject-events - The task is about narrative/lore data, not engine code — use
worldbuilding-lore-systems
Operating procedure
- Respect the lifecycle.
for self-initialization andAwake
caching.GetComponent
for cross-object setup.Start
for physics.FixedUpdate
for input/frame logic.Update
for camera follow.LateUpdate
for cleanup and unsubscription.OnDestroy - Compose with components. Favor composition over inheritance. Use
to enforce dependencies. Access siblings via cached[RequireComponent(typeof(Rigidbody))]
inGetComponent<T>()
, never inAwake
.Update - Use ScriptableObjects for data. Create asset instances with
. Use for shared config (weapon stats, enemy profiles), runtime sets, and event channels. Never store scene-specific state in SOs.[CreateAssetMenu(fileName="New X", menuName="Game/X")] - Load assets with Addressables. Mark assets addressable in the inspector. Load via
. Release withAddressables.LoadAssetAsync<GameObject>("key")
. Group by load context, not asset type.Addressables.Release(handle) - New Input System. Define actions in an InputActionAsset. Reference via
component or generated C# class. Bind withPlayerInput
. Support rebinding withaction.performed += ctx => { }
.InputActionRebindingExtensions - Physics. Apply forces in
. Use layers andFixedUpdate
for selective raycasts. PreferLayerMask
. Use triggers (Physics.Raycast(origin, dir, out hit, maxDist, layerMask)
) for detection zones.OnTriggerEnter - Coroutines and async. Use
+StartCoroutine
for simple delays. For complex async, useyield return new WaitForSeconds(t)
withasync/await
orUniTask
(Unity 2023+). Always stop coroutines on disable.Awaitable - Project structure. Use Assembly Definitions to control compilation. Separate
,Runtime/
,Editor/
assemblies. UseTests/
guards for editor-only code. Nest prefab variants for shared base + specialization.#if UNITY_EDITOR - Common C# patterns. Use
over public fields. Group inspector fields with[SerializeField] private
. Implement object pools with[Header("Movement")]
. Use events (Queue<T>
,System.Action
) for decoupling. Avoid singletons except for service locators.UnityEvent - Profile and optimize. Use Unity Profiler and Frame Debugger. Minimize allocations in
(noUpdate
, no LINQ, no string concat). Batch draw calls with static/dynamic batching. UseGetComponent
fromObjectPool<T>
.UnityEngine.Pool
Decision rules
- Cache all
calls inGetComponent
; never call them per-frame.Awake - Prefer
over[SerializeField] private
fields — expose to inspector without breaking encapsulation.public - Use ScriptableObjects for data shared across scenes; use MonoBehaviours for scene-specific behavior.
- Choose Addressables over
for any project beyond a prototype.Resources.Load - Use Assembly Definitions in any project with more than ~10 scripts to cut recompile times.
- For physics-driven gameplay, all movement goes through
inRigidbody
, neverFixedUpdate
inTransform.Translate
.Update
Output requirements
— complete C# file with correctScript
statements, namespace, and Unity attributesusing
— which MonoBehaviour callbacks are used and whyLifecycle
— required components, packages (Addressables, Input System, etc.)Dependencies
— serialized fields, headers, component configurationInspector Setup
— allocation concerns, caching strategy, profiler targetsPerformance Notes
References
- Unity Scripting API
- Unity Manual — Order of Execution
- Addressables Documentation
- Input System Manual
- UI Toolkit Documentation
- DOTS/ECS
Related skills
— SO-based event architecture patternsunity-scriptableobject-events
— when comparing Unity vs Unreal approachesunreal-engine
— higher-level game system designgame-design-systems
Failure handling
- If
returns null, check that the component exists on the same GameObject or useGetComponent
.TryGetComponent - If Addressables load fails, verify the asset is marked addressable and the catalog is built (
).Addressables.InitializeAsync() - If Input System actions don't fire, confirm the PlayerInput component is set to the correct action map and the InputActionAsset is assigned.
- If physics interactions are missed, check that at least one object has a non-kinematic Rigidbody, colliders are not set to trigger incorrectly, and layers are in the collision matrix.