mcpField
U
unity-composition-pattern

unity-composition-pattern

github.com/muharremtozanDevelopment1753 installsUpdated 22w ago
Repository

About unity-composition-pattern

unity-composition-pattern is a Unity design skill for modeling entities by composing ScriptableObject configurations instead of creating inheritance-heavy class hierarchies. It is aimed at developers who need interchangeable entity behavior and data with fewer specialized classes.

Key features

  1. 01Has-a composition model
  2. 02ScriptableObject-to-runtime instances
  3. 03Tuple-based multi-value returns
  4. 04Fewer specialized C# files

Use cases

  1. 01Represent entity variations with configuration assets
  2. 02Create runtime entities from ScriptableObject templates
  3. 03Return multiple values from composite behavior

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/muharremtozan/unity-agent-skills --skill unity-composition-pattern

After installing, type/unity-composition-patternin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

assets/code/
CompositionExample.cs.txt
EntityConfigSO.cs.txt
ModularEntity.cs.txt

Details

From the project README

Unity Composition Pattern

A fundamental design skill to prevent "Inheritance Hell." This pattern replaces 10 specific classes (e.g., RedStone, GoldStone) with one generic class that composes behaviors from ScriptableObject assets.

Core Features

  1. Has-A Logic: Objects define their properties through members (Configs) rather than their base class type.
  2. SO-to-Runtime Bridge: Uses ScriptableObjects as static data templates that generate dynamic runtime instances.
  3. Tuple Deconstruction: Uses C# ValueTuples to return multi-part data from composite objects without extra boilerplate.
  4. Hierarchy Flattening: Drastically reduces the number of C# files needed by offloading variations to Project Assets.

Core Files (Max 3)

  • EntityConfigSO.cs.txt: Base class for creating interchangeable data packets.
  • ModularEntity.cs.txt: The generic container that holds one or more configurations.
  • CompositionExample.cs.txt: Demonstrates resource harvesting with Tuple destructuring.

Usage

1. Identify "Is-A" vs "Has-A"
  • Bad: ElectricCar : Car : Vehicle (Inheritance)
  • Good: Vehicle has an EngineConfig (Composition)
2. Multi-Value Returns (Tuples)

Instead of internal state-tracking:

public (int gold, int weight) Gather() => (10, 5);
// Client destructures instantly:
var (g, w) = node.Gather();
3. Strategy via SO

Attach different EntityConfigSO assets to the same ModularEntity to change its identity in the Inspector.

Comments

Markdown supported