skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
besty0728/unity-skills92 installs

unity-patterns

Advise on choosing Unity design patterns

How do I install this agent skill?

npx skills add https://github.com/besty0728/unity-skills --skill unity-patterns
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    This skill is a documentation-only resource providing architectural advice for Unity design patterns. It contains no executable code, network operations, or security risks.

  • Socketpass

    No alerts

  • Snykpass

    Risk: LOW · No issues

  • Runlayerpass

    1 file scanned · No issues

What does this agent skill do?

Unity Pattern Selector

Documentation only: no REST skills. Use to decide whether a pattern is justified. Do not recommend every pattern at once.

When to use

  • Deciding which pattern fits a problem
  • Structuring decoupled systems
  • Choosing event, state-machine or pool approaches

Pattern guide

  • ScriptableObject
    • Use for authored config, shared static data, event channels, and reusable data assets.
    • Avoid as the default home for per-run mutable gameplay state.
  • C# events / delegates
    • Use for one-to-many notifications with clear ownership and unsubscribe points.
    • Avoid for imperative flows that need ordering, return values, or complex debugging.
  • Global event bus / observer hub
    • Use sparingly, only when many systems truly need broad decoupled notifications.
    • Avoid as the default answer to coupling. It often hides ownership and makes debugging harder.
  • Interfaces
    • Use when multiple implementations or clearer dependency boundaries are needed.
    • Avoid adding interfaces around every class without a real seam.
  • State machine
    • Use for actors with mutually exclusive states and explicit transitions.
    • Avoid when a few booleans or a small command flow is enough.
  • Object pool
    • Use for frequent spawn/despawn of bullets, VFX, enemies, UI items.
    • Avoid for rare objects or when lifetime is simple.
  • Service layer
    • Use for a small number of cross-scene systems with explicit bootstrap and interfaces.
    • Avoid turning everything into hidden singletons or service locators.
  • Generics / custom attributes
    • Use when they remove repeated boilerplate with clear type safety or editor metadata value.
    • Avoid when they make gameplay code harder to read than duplicated simple code.

Decision lab: same goal, multiple implementations

For a non-trivial design decision, pick the 2-3 plausible implementations, put them side by side, and compare switch cost, query cost, code complexity and failure modes. Worked example below; use it as the shape for other decisions, not as the answer.

Worked example: "Pause AI on 100 enemies for a cutscene"

ImplementationSwitch cost (enter/exit cutscene)Per-frame cost while pausedCode complexityFailure modes
Field flag: each EnemyAI.Update starts with if (_paused) return;; manager sets the flagO(N) writes, no allocationsN branch tests + dispatch overhead per frameLowest: one bool, one guard clauseSilent bugs when a dev adds a new Update and forgets the guard
enabled = false: manager disables the MonoBehaviour on every enemyO(N) writes, no allocationsZero: Unity skips disabled Behaviours in its message listLow, but state spread across componentsOnDisable / OnEnable side effects (coroutines stop, listeners unsubscribe) may fire unexpectedly
Subset list: manager keeps _active / _frozen lists; no per-enemy Update, manager ticks only _activeO(N) list move on switchProportional to _active count only: early cullHighest: one source of truth for ownership, requires managed tickingAdding a new Update on enemies reintroduces per-frame cost; the list desyncs easily if other code respawns enemies directly

How to use:

  • Pick the smallest scale where the trade-off matters. At N=5 all three are indistinguishable; at N=5000 only the subset list stays flat.
  • State what gets worse under each option, not only what improves.
  • The same three shapes (value change, structural change, enableable) recur in ECS; the labels transfer even when the framework does not. Source: Dots101/Entities101/Assets/HelloCube/13. StateChange/SetStateSystem.cs:42-80.

Skip this exercise when one option is obviously bounded (N <= 10, state changes once per session, or the code runs once at startup). A single sentence saying "we picked X because it's simplest" is enough.

Output format

  • Recommended pattern(s), at most 1-3
  • Why they fit this case
  • Why not the simpler alternative
  • Minimal implementation boundary
  • Known tradeoffs

Pitfalls

  • Explain why simpler options are not enough before recommending a pattern.

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/besty0728/unity-skills/unity-patterns">View unity-patterns on skillZs</a>