unity-patterns

Recommends Unity design patterns for decoupled systems and gameplay architecture decisions.

2|Updated May 18, 2026
One-click install
npx skills add https://github.com/pcone-mm/NewFPG --skill unity-patterns-pcone-mm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-patterns
Source: https://github.com/pcone-mm/NewFPG/tree/main/.agents/skills/unity-skills/skills/patterns
Command: npx skills add https://github.com/pcone-mm/NewFPG --skill unity-patterns-pcone-mm

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing the right design pattern in Unity is hard: overusing event buses, singletons, or state machines leads to hidden coupling and debugging pain. This Skill helps you decide which pattern actually fits your problem and when a simpler approach is enough. ## Core Features & Use Cases - Pattern Selection Guidance: Compares ScriptableObject, C# events, event buses, interfaces, state machines, object pools, service layers, and generics with explicit use/avoid criteria. - Decision Lab Method: Provides a side-by-side comparison framework (switch cost, per-frame cost, complexity, failure modes) for non-trivial design decisions, illustrated with a worked example of pausing 100 enemies. - Use Case: When you ask "should I use a state machine for my enemy AI?" or "事件总线还是直接引用?", the Skill recommends at most 1-3 patterns, explains why simpler options fall short, and lists known tradeoffs. ## Quick Start Ask the assistant which Unity design pattern fits your problem, for example whether to use an object pool or direct instantiation for bullet spawning.

Frequently Asked Questions about unity-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose the right design pattern in Unity?

Match the pattern to the problem shape: ScriptableObjects for shared config data, C# events for one-to-many notifications, state machines for mutually exclusive states, and object pools for frequent spawning. Recommend at most 1-3 patterns and explain why simpler options are not enough.

When should I use a state machine in Unity?

Use a state machine when an actor has mutually exclusive states with explicit transitions, such as enemy AI behaviors. Avoid it when a few booleans or a small command flow is sufficient, since the added structure only pays off at real complexity.

Should I use an event bus or direct references in Unity?

Use a global event bus sparingly, only when many systems genuinely need broad decoupled notifications. It often hides ownership and makes debugging harder, so prefer C# events with clear ownership and unsubscribe points for most one-to-many cases.

When is object pooling worth it in Unity?

Object pooling pays off for frequent spawn and despawn cycles like bullets, VFX, enemies, and UI items. Avoid it for rare objects or simple lifetimes, where direct instantiation is simpler and the pooling overhead gains nothing.

What are the downsides of ScriptableObjects for game state?

ScriptableObjects work well for authored config, shared static data, and event channels, but they are a poor default home for per-run mutable gameplay state. Mutable state in assets can persist unexpectedly between play sessions in the editor.