UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / Event System Completed

Utility Systems — UGTK

Event System

Summary

The Event System lets objects talk to each other by name, without holding references. A controller owns a pool of event objects; you activate one under a name, anybody subscribes to that name, anybody invokes it. Sender and receiver never need to know about each other, and neither has to exist when the other is wired up.

The event objects are pooled, so creating and dropping events during play does not allocate.

Only the zero-parameter event is usable today. Mn_Event_OneParameters<T> and Mn_Event_TwoParameters<T,T1> exist in the code but ship with no controller and no prefab: to use them you have to write the controller yourself.


Content


Modules Dependencies


Setup

A single event. Drop the EventZeroParameters prefab into the scene:

Give it a name — this is the key everything else will use, and setting it also renames the GameObject:

Then wire the listeners from the inspector, exactly like a UnityEvent:

A controller, when events are created and destroyed at runtime. Drop the ZeroParametersController prefab:

Optionally associate its Animator, so an animation can raise the events by name:

The custom inspector can activate, deactivate and invoke events while playing, so the wiring can be checked without writing any calling code:


How To Use

Mn_ZeroParametersController events;

events.ActiveNewEvent("DoorOpened");                     // take one from the pool under this name
events.SubScribeToEvent("DoorOpened", myListener);       // note the capital S in "SubScribe"
events.InvokeEvent("DoorOpened");
events.UnSubscribeToEvent("DoorOpened", myListener);
events.DeactiveEvent("DoorOpened");                      // give it back to the pool

On a single Mn_Event_ZeroParameters you can also call AddListener / RemoveListener / Invoke directly, plus ActiveEvent / DeactiveEvent and GetName / SetName.

Good to know:


Testing Scene

Open Debug/EventSceneExample.unity: EventUserExample subscribes to an event and reacts to it, so you can watch the whole activate → subscribe → invoke cycle in the console.


Technical Info

Path Content
Scripts/Runtime/Events/Mn_Event.cs Abstract base: name, active flag, ActiveEvent / DeactiveEvent, GetName / SetName
Scripts/Runtime/Events/List/Mn_Event_ZeroParameters.cs The usable event: AddListener, RemoveListener, Invoke
Scripts/Runtime/Events/List/Mn_Event_OneParameters.cs Generic one-parameter event — no controller ships for it
Scripts/Runtime/Events/List/Mn_Event_TwoParameters.cs Generic two-parameter event — no controller ships for it
Scripts/Runtime/Controllers/Mn_EventsController.cs Generic controller: pool, ActiveNewEvent, DeactiveEvent, lookup by name
Scripts/Runtime/Controllers/List/Mn_ZeroParametersController.cs Concrete controller: SubScribeToEvent, UnSubscribeToEvent, InvokeEvent
Scripts/Runtime/UnityEventExtensions.cs ContainsMethod: checks whether a UnityEvent already holds a given persistent listener
Debug/EventUserExample.cs Example subscriber used by the test scene

© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 3 modules in total.