event-systems

Design Unity/C# event-driven communication with deterministic lifecycle unsubscription.

Updated May 6, 2026
One-click install
npx skills add https://github.com/BasarEkinci/memory-card-game --skill event-systems-basarekinci
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: event-systems
Source: https://github.com/BasarEkinci/memory-card-game/tree/main/.claude/skills/core/event-systems
Command: npx skills add https://github.com/BasarEkinci/memory-card-game --skill event-systems-basarekinci

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Event systems prevent tight coupling between game systems by letting publishers broadcast changes without knowing subscribers, while also reducing bugs caused by forgotten subscriptions and leaked delegates.

Core Features & Use Cases

  • Compare event options: C# events/Action for code-only communication, UnityEvent for designer-wired callbacks, ScriptableObject (SO) event channels for cross-system messaging, and a static EventBus for rare global events.
  • Enforce correct lifecycle handling: Subscribe in OnEnable and unsubscribe in OnDisable to avoid memory leaks across disable/destroy/scene unload.
  • Use zero-allocation patterns when needed: Apply special structures for hot paths (e.g., ref-friendly event payloads) rather than allocating per event in performance-critical scenarios.
  • Common mistakes prevention: Avoid subscribing in Start/Awake without guaranteed cleanup, avoid using events where a direct method call is simpler, and avoid overusing global event buses.

Quick Start

Use the event-systems skill to pick the right Unity event pattern for your publisher-subscriber need, then implement symmetric subscribe/unsubscribe in OnEnable/OnDisable to keep your scene transitions leak-free.

Frequently Asked Questions about event-systems

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

FAQPage Schema
How do I prevent memory leaks caused by C# events in Unity?

To prevent memory leaks in Unity event systems, subscribe to C# events in OnEnable and unsubscribe in OnDisable. This enforces deterministic cleanup across disable, destroy, and scene unload transitions to prevent leaked delegates.

What's the best way to decouple gameplay logic in Unity?

The best way to decouple Unity gameplay logic is using event-driven communication. Publishers broadcast changes without knowing subscribers, utilizing C# events, UnityEvent, ScriptableObject event channels, or a static EventBus based on your specific use case.

When should I use UnityEvent versus ScriptableObject event channels?

Use UnityEvent for designer-wired UI callbacks in the Inspector, and ScriptableObject event channels for cross-system or cross-scene messaging. C# events suit code-only communication, while a static EventBus fits rare global events.

How do I avoid memory allocations in Unity performance-critical event hot paths?

To avoid memory allocations in Unity event hot paths, apply zero-allocation patterns using special structures and ref-friendly event payloads. This prevents per-event garbage generation in performance-sensitive gameplay state updates.

Why does my Unity scene still hold references after unloading?

Your Unity scene holds references after unloading due to forgotten event subscriptions. Subscribing in Start or Awake without guaranteed cleanup in OnDisable causes memory leaks; enforce symmetric subscribe and unsubscribe lifecycle methods.