unity-patterns

A collection of example patterns for writing Unity game components in C#. Unity is a game engine, and a component is a script attached to an object in a game.

In plain words
What is it for?
Use it when writing Unity behaviours such as player movement, physics checks, input handling, and event subscriptions.
Why use it?
It gives developers a consistent structure for component fields, cached references, and event setup and cleanup.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/hermeticormus/libregamedev-claude-code/unity-patterns
Any agent
npx skills add HermeticOrmus/LibreGameDev-Claude-Code --skill unity-patterns
Clone the repo
git clone --depth 1 https://github.com/HermeticOrmus/LibreGameDev-Claude-Code

Made for: Claude Code, Codex.

Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,746 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01746
Opus 5 $0.00000 $0.00873
Sonnet 5 $0.00000 $0.00349
Haiku 4.5 $0.00000 $0.00175

Measured 2d ago against content hash bec0f886b9a5, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unity-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/unity-development/skills/unity-patterns/SKILL.md · 254 lines

How it starts

The opening of the file, as written. The whole thing — 254 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Unity Patterns

MonoBehaviour Component Pattern

// Well-structured MonoBehaviour: serialized fields, cached references, event lifecycle
using UnityEngine;

[RequireComponent(typeof(Rigidbody), typeof(Collider))]
public class PlayerController : MonoBehaviour
{
    [Header("Movement")]
    [SerializeField] private float _moveSpeed = 6f;
    [SerializeField] private float _jumpForce = 8f;

    [Header("Ground Check")]
    [SerializeField] private LayerMask _groundMask;
    [SerializeField] private Transform _groundCheck;
    [SerializeField] private float _groundCheckRadius = 0.2f;

    // Cached component references - filled in Awake, never in Update
    private Rigidbody _rb;
    private bool _isGrounded;
    private Vector2 _moveInput;

    private void Awake()
    {
        _rb = GetComponent<Rigidbody>();
    }

    private void OnEnable()
    {
        // Subscribe to input or events here
    }

    private void OnDisable()
    {
        // Unsubscribe here - prevents memory leaks
    }

    private void Update()
    {
        _moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        _isGrounded = Physics.CheckSphere(_groundCheck.position, _groundCheckRadius, _groundMask);

        if (_isGrounded && Input.GetButtonDown("Jump"))
        {
            _rb.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse);
        }
    }

    private void FixedUpdate()
    {
        // Physics forces go in FixedUpdate
        Vector3 move = transform.right * _moveInput.x + transform.forward * _moveInput.y;
        _rb.MovePosition(_rb.position + move * _moveSpeed * Time.fixedDeltaTime);
    }
}

ScriptableObject Event Channel

// Decoupled event system using ScriptableObject channels (Ryan Hipple pattern)
using System;
using UnityEngine;

[CreateAssetMenu(menuName = "Events/Game Event")]
public class GameEventSO : ScriptableObject
{
    private Action _listeners;

    public void Raise()
    {
        _listeners?.Invoke();
    }

    public void Subscribe(Action listener) => _listeners += listener;
    public void Unsubscribe(Action listener) => _listeners -= listener;
}

// Generic version for typed events
[CreateAssetMenu(menuName = "Events/Float Event")]
public class FloatEventSO : ScriptableObject
{
    private Action<float> _listeners;

    public void Raise(float value) => _listeners?.Invoke(value);
    public void Subscribe(Action<float> l) => _listeners += l;
    public void Unsubscribe(Action<float> l) => _listeners -= l;
}

// Usage: MonoBehaviour subscribes/unsubscribes via lifecycle
public class HealthDisplay : MonoBehaviour
{
    [SerializeField] private FloatEventSO _healthChangedEvent;

    private void OnEnable() => _healthChangedEvent.Subscribe(OnHealthChanged);
    private void OnDisable() => _healthChangedEvent.Unsubscribe(OnHealthChanged);

    private void OnHealthChanged(float newHealth)
    {
        // Update UI
    }
}

Read the full file on GitHub · 254 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 254 lines · 0 tokens per session scan A bec0f886b9a5

Subscribe to this mod's changes

unity-patterns is a skill published in the GitHub repository HermeticOrmus/LibreGameDev-Claude-Code (6 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,746 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

luban-dev

Luban 游戏配置全栈工具,支持枚举/Bean/数据表的增删改查、代码生成、TEngine 集成。触发场景:(1) 编辑游戏配置数据(配置表/数据表/道具表/技能表/奖励表/活动表),(2) 新增/修改/删除配置表结构,(3) 定义枚举/Bean/字段,(4) 导表/生成配置代码,(5) 编写 luban.conf 或 Schema 定义,(6) Luban 类型系统/校验器问题。即使用户未明确说"Luban",只要是编辑游戏配置数据,也应使用此技能。.

Alex-Rachel/TEngine · 149 tokens

html-to-ugui

HTML 原型转 Unity UGUI 智能 Prefab 生成管线。通过 AI 生成符合 UI-DSL 的 HTML,用 Playwright/浏览器烘焙 JSON v2 坐标、图片和适配意图,再导入 Unity 由 HtmlToUGUIBaker 生成可维护、多终端适配的 UGUI Prefab。触发场景:(1) 需要从自然语言生成 Unity UGUI 界面 (2) 需要从 HTML 原型烘焙 UGUI (3) UI 中包含图片并希望一键导入/绑定 Sprite (4) 需要 PC/mobile/pad 多终端适配 Prefab。.

Alex-Rachel/TEngine · 150 tokens

tengine-dev

TEngine Unity 游戏框架开发指导。触发词:TEngine, UIWindow, UIWidget, GameEvent, AddUIEvent, LoadAssetAsync, SetSprite, HybridCLR, YooAsset, Luban, GameModule, 热更, 资源加载, UI开发, 事件系统, 配置表.

Alex-Rachel/TEngine · 68 tokens

ai-system

AI system for game entities including behavior trees, finite state machines, steering behaviors, and decision making.

bullish0x/GameStudio · 22 tokens

godot-2d-animation

Expert patterns for 2D animation in Godot using AnimatedSprite2D and skeletal cutout rigs. Use when implementing sprite frame animations, procedural animation (squash/stretch), cutout bone hierarchies, or frame-perfect timing systems. Trigger keywords: AnimatedSprite2D, SpriteFrames, animationfinished…

bgrenat/godot-game-dev-studio · 109 tokens

godot-2d-physics

Expert patterns for Godot 2D physics including collision layers/masks, Area2D triggers, raycasting, and PhysicsDirectSpaceState2D queries. Use when implementing collision detection, trigger zones, line-of-sight systems, or manual physics queries. Trigger keywords: CollisionShape2D, CollisionPolygon2D, collisionlayer…

bgrenat/godot-game-dev-studio · 138 tokens