UGTK / Toolkit / Utility Systems / Event System Completed
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>andMn_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
- Pooling System: the controller takes its event objects from a pooler instead of instantiating them.
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:
- ⚠️ The method is
SubScribeToEvent, with a capital S in the middle. Its counterpart is spelled normally,UnSubscribeToEvent. Autocomplete will not find the first one if you typeSubscribe. - An inactive event swallows the invoke silently.
Invoke()checks theactiveflag and returns without doing anything: an event you forgot to activate — or that you already deactivated — fails quietly, with no warning. This is the first thing to check when "the event does not fire". - The name is the contract. Nothing checks it: a typo in
InvokeEventraises nothing and reports nothing. Keep the names in constants rather than in string literals scattered around. ActiveNewEventreally does take a new one from the pool: calling it twice with the same name gives you two distinct events sharing that name, and the lookup returns the first. Activate once.SetNamerenames the GameObject too, so events are easy to find in the Hierarchy while debugging.- Deactivating returns the object to the pool: its listeners are gone with it, and re-activating the same name gives you a clean event. Do not expect the subscriptions to survive.
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
Depends on 1
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 3 modules in total.
UGTKengine within an engine


