Game Event Hub - Attribute based Event System

Asset store link

Hi everyone :wave:!

I’m really excited to announce the release of my asset Game Event Hub.

For years, I’ve been experimenting, refining, and building different systems to effectively “glue” components together without relying on hard references. Game Event Hub represents the culmination of these efforts — an elegant, robust event system that simplifies communication between components using plain C# classes. :smile:

:sparkles: Key features

Game Event Hub is designed to eliminate the need for unnecessary hard references between different systems by offering a powerful event system. Inspired by popular modding tools from games like Minecraft, Cyberpunk, and others, this asset uses annotations (attributes) to bind methods to events—making your code crystal-clear and easy to follow. Here’s a quick overview of how it works:

Event definition:

public class OnStep : GameEvent // <-- Game Event is a plain C# class
{
    public bool isLeftFoot;
    public Transform footTransform; // <-- I can include all the fields I need as payload
    
    public OnStep()
    {
    }

    public OnStep(bool isLeftFoot)
    {
        this.isLeftFoot = isLeftFoot;
    }
}

Event emission:

public MyScript: MonoBehaviour 
{

    public void SomeFunctionThatDetectsPlayerStep()
    {
        new OnStep(true, footGameobject).Publish(this); // <-- Just emit with this line
    }
}

Event subscription:

public MyScriptThatPlayStepSound: MonoBehaviour 
{
        private void OnEnable()
        {
            GameEventHub.Bind(this); // <-- This triggers the binding between methods and events
        }

        private void OnDisable()
        {
            GameEventHub.Unbind(this); // <-- This cleans the binding
        }

        [OnGameEvent] // <-- Here is the magic
        private void PlaySound(OnStep e) // <-- Event subscribed based on first argument
        {
             // Do something here with the event
        }

        [OnGameEvent(typeof(OnStep))] // <-- With explicit typeof
        private void AnotherHandler()
        {

        }

        [OnGameEvent(SubscriberPriority.Essential)] // <-- With explicit subscriber priority
        private void AnotherHandler(OnStep e)
        {

        }

}

Before you think “oh… just another event system”, Game Event Hub brings so much more to the table:

  • Cancel event propagation: Stop the propagation to further subscribers when necessary.

  • Shared and Unique events:

    • Shared: Subscribers can modify the event data and see each other’s changes.
    • Unique: Each subscriber gets their own copy of the payload.
  • Subscriber priority: Define event propagation order with Essential, High, Medium, Low, and Cleanup priorities. This ensures fine-grained control over event handling.

  • Delayed event publishing: Easily schedule events for later execution with time delays.

  • Custom filters: Filter event subscribers dynamically based on runtime conditions to control exactly who receives the event. For example:

For example:

new OnStep(true)
                .WithFilter(new WithTag("Player")) // <-- Only subscribers with this tag
                .WithFilter(new InsideCollider2D(collider2D)) // Only subscribers inside the collider
                .WithFilter(new SameSceneAsEmitter()) // Only subscribers in the same scene as the emitter
                .Publish(this);

:hammer_and_wrench: Tools to Simplify Debugging and Testing:

To help you manage and debug your events effortlessly, I’ve included three powerful tools:

  1. Monitor: Visualize and track all active event subscribers for greater clarity.

  2. Log: View event activity, including when events are raised and when subscribers are bound/unbound.

  3. Tester: Trigger events manually and configure serializable fields in the editor—a must-have for testing complex scenarios.

:books: Comprehensive Documentation:

Last but no least, I know that a tool is as good as its documentation, so I put a lot of effort to create an editor embedded documentation. This system is not only easy to read but also expandable by users for their own custom notes, thanks to its Markdown support and a custom editor view:

The future

I have plans to continue working on the asset, here are a few ideas that I’m working on:

  • Abstract Event Propagation Mechanism: Enable support for advanced workflows such as multithreaded event propagation or even propagation across networks.
  • SerializeReference Support in the Tester Tool: Add the ability to manually raise events with complex data types (e.g., interfaces, classes) and enable recursive serialization of their properties for easier testing and debugging.
  • Animation Events Integration: Allow events to be emitted directly from animations (similar to Unity’s Animation Events).
  • Timeline Integration: Support the emission of custom events from Unity Timeline assets.
  • Event Rejection on Subscriber Side: Give subscribers the option to reject events based on logic or conditions to provide greater flexibility.
  • Improved Inspectors and Debugging Tools: Further enhance the inspectors and tools to make tracking, debugging, and managing events even more intuitive.

TL;DR

Game Event Hub is a powerful event system for Unity that simplifies communication between components. Create, emit, and handle events with ease—and take advantage of advanced features like delayed publishing, filters, and priority control.

:point_right: Get it now on the Asset Store, RELEASE DISCOUNT!

30% OFF Only 3 days left!

30% OFF LAST DAY!

Also update 1.1.1 is alive!

General

  • Migrated tools from IMGUI to UI Toolkit
  • Improved documentation
  • Improved event inspectors
  • Added GameEventSO (Mechanism to save and trigger game events from scriptable objects)
  • Adjusted namespaces
  • Added StopPropagation(object canceller)
  • Deprecated StopPropagation() -please use the above-

Tools

  • Improved tester tool

    • Emit with filters
    • Load events saved in ScriptableObjects
  • Improved log tool

    • Filter log (extendable)
    • Contextual actions on lines
    • Greatly Improved performance
  • Improved event subscribers / emitter tool:

    • Added ability to ping ScriptableObjects
  • Improved subscription monitor

    • Removed dependency on Editor.Coroutines
    • Greatly improved performance