A type-safe, zero-allocation event bus for Unity. Decoupled communication, thread-safe queues, async/await support, and a live editor debugger. Full C# sourcecode.- DEMO -- DOCS -_______________Stop Writing Spaghetti. Start Building Systems.Every growing Unity project hits the same wall: components calling each other directly, fragile references breaking on prefab changes, and event spaghetti that's impossible to debug. Unity EventBus solves this with a clean, production-ready event-driven architecture that keeps your systems completely decoupled and your codebase maintainable at any scale._______________Why Developers Choose Unity EventBusZero Allocation on the Hot PathEvents are structs dispatched through a pre-built snapshot array. No boxing, no per-frame heap allocations, no GC spikes even under thousands of events per second (see the StressTest sample).Type-Safe by DesignStrongly-typed events via the IEvent interface catch mismatches at compile time, not at runtime.Thread-Safe Out of the BoxPublish from background threads, Jobs, or async tasks using PublishFromThread or the EventQueue system. Events are buffered and safely dispatched to the main thread every frame, no manual marshalling required.Async/Await SupportWait for a specific event without coroutines or polling. Full cancellation token support keeps async flows clean and leak-free.Automatic Memory SafetyOwner-tracked subscriptions are automatically cleaned up when a MonoBehaviour is garbage-collected.Live Editor DebuggerThe built-in Event Bus Debugger window shows every registered event type, live subscriber counts, and a rolling publish log all in real time. Debug event flow without adding a single line of instrumentation code.Event FilteringSubscribe with a predicate to receive only the events that matter to a specific system. Filter by player ID, team, damage type, or any field on the event._______________What's IncludedThe package ships with a complete runtime system covering the core bus, thread-safe event queues, owner-tracked bindings, and automatic lifecycle management. Editor tools include a live debug window and editor bridge for custom workflows.Four sample scenes with full source code cover every major use case:Basic - publisher/subscriber fundamentals, ideal starting pointArena - full gameplay demo with decoupled player, drone, and HUD systemsStressTest - high-frequency performance validation under heavy event loadThreaded - safe event dispatch from background threads_______________Built for ProfessionalsFull C# sourcecode. Assembly definitions keep compile times fast and project structure clean. Compatible with Unity 2021.3 LTS through Unity 6. No external dependencies.Zero-Allocation Publish PathThe publish hot path performs a single volatile reference read on a pre-built snapshot array. Events are passed by reference (ref T) so struct data is never copied during dispatch.Lock-Free Reads, Lock-Protected WritesSubscribe, Unsubscribe, and the dead-binding sweep are lock-protected and rebuild a stable snapshot array. Publish reads that snapshot with a single atomic volatile read, completely lock-free on the critical path even with concurrent mutations.Snapshot-Based DispatchSubscribers are stored in a sorted snapshot array rebuilt only on mutations. Dispatch iterates the snapshot, meaning subscribe and unsubscribe during publish is safe and takes effect next frame.Priority OrderingEach binding carries an integer priority. Higher values fire first within a single Publish call, giving fine-grained control over handler execution order without additional wiring.Weak-Reference Owner TrackingOwner-tracked bindings store the subscriber as a WeakReference. The per-frame sweep pass checks liveness and prunes collected bindings automatically.ConcurrentQueue-Backed Cross-Thread PublishPublishFromThread enqueues into a ConcurrentQueue, lock-free on the enqueue side. The EventBusLifecycle PlayerLoop injection drains it on the main thread at the top of every Update, before the dead-binding sweep.PlayerLoop InjectionThe lifecycle system uses RuntimeInitializeOnLoadMethod(BeforeSceneLoad) to inject a custom sweep step directly into Unity's PlayerLoop Update phase. No scene object or singleton MonoBehaviour is required.Filter Predicates Passed by in ReferenceEvent filters receive the event via an in parameter, a read-only reference with no struct copy. Filters that reject an event incur no handler invocation cost.One Allocation Per Event TypeInternal delegates are cached as static readonly fields on the generic class, allocated once per event type at first use.


