About unity-observer-pattern
Unity Observer Pattern (Reactive Properties) is a Unity implementation of the Observer pattern that wraps variables as observable properties. It supports both C# listeners and UnityEvents, with Inspector support and Edit-mode wiring that persists to scenes and prefabs.
Key features
- 01C# listener and UnityEvents paths
- 02Implicit conversion from observable values
- 03Inspector-based event setup
- 04Persistent Edit-mode event wiring
- 05Structured event-flow logging
Use cases
- 01Notify UI methods when a value changes
- 02Subscribe to property changes from C# code
- 03Save event connections into a scene or prefab
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ muharremtozan/ unity-agent-skills --skill unity-observer-patternAfter installing, type/unity-observer-patternin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
assets/code/Observable.cs.txtObservableEditorTools.cs.txtObservableExample.cs.txtreferences/guide.mdDetails
From the project READMEUnity Observer Pattern (Reactive Properties)
A powerful implementation of the Observer pattern that turns standard variables into "Smart Properties." Includes full Inspector support and Edit-mode tooling based on the "Generic Observer" architecture.
Core Features
- Hybrid Path: Works with standard C# listeners (Pro Path) AND UnityEvents (Designer/Light Path).
- Implicit Casting: Seamless syntax allows
int x = myObservableInt;(no more.Valueboilerplate). - Editor Persistence: Programmatically wire persistent calls in Edit Mode that save to scene/prefab.
- Diagnostic Logging: Built-in structured logging for tracking event flows.
Core Files (Max 3)
Observable.cs.txt: The core generic wrapper with implicit casting and built-in editor wiring.ObservableEditorTools.cs.txt: Advanced reflection hacks for clearing persistent UnityEvents.ObservableExample.cs.txt: Concrete example demonstrating UI binding and lifecycle management.
Usage
Option A: The Light Path (Inspector)
- Define a field:
public Observable<int> health;. - In Unity Inspector, drag your UI method into the
On Value Changedlist.
Option B: The Pro Path (Code)
health.AddListener( val => Debug.Log( val ) );
health.Value = 50; // Automatically triggers notification
Option C: Implicit Usage
int currentHealth = health; // Works automatically via implicit operator
Cleanup
Always call RemoveListener or Dispose in OnDisable to prevent memory leaks.
Comments
Markdown supported