Unity Event Binder¶
The UnityEventBinder is a crucial MonoBehaviour component that bridges the gap between SOAR's GameEvents and Unity's built-in UnityEvent system.
Often called an "Event Listener," it listens for a GameEvent asset and, in response, invokes a UnityEvent, allowing for game logic to be wired up directly in the Inspector without code.
Core Concept¶
The UnityEventBinder is a MonoBehaviour that is attached to a GameObject in a scene. It has two main purposes:
- Listen to a
GameEvent: A specificGameEventasset is assigned to the binder. - Trigger a
UnityEvent: When the specifiedGameEventis raised, the binder invokes aUnityEventthat can be configured in the Inspector.
This creates a powerful and decoupled workflow. The object raising the GameEvent doesn't need to know anything about the objects that will react to it, and vice-versa.
UnityEventBinder (for parameterless GameEvents)¶
The non-generic UnityEventBinder is used for GameEvents that do not carry any data.
How to Use¶
-
Add the Component: A
GameObjectin a scene is selected and theUnityEventBindercomponent is added to it (Add Component > SOAR > Unity Event Binder). -
Assign the GameEvent: In the Inspector, a parameterless
GameEventasset is dragged and dropped into theGame Event To Listenfield.
-
Configure the UnityEvent: The
On Game Event RaisedUnityEventis configured.GameObjects or components can be dragged into the event slot and a public method can be selected to be called when the event is raised.
Now, whenever the assigned GameEvent is raised (from a script, another UnityEvent, or the Inspector), the UnityEventBinder will invoke the configured methods.
UnityEventBinder<T> (for GameEvents with data)¶
The generic UnityEventBinder<T> is used for GameEvent<T>s that carry a data payload. SOAR provides a set of pre-built binders for common types.
Pre-built Binders¶
Pre-built binders for various types can be found under Add Component > SOAR > Unity Event Binders:
BoolUnityEventBinderByteUnityEventBinderDoubleUnityEventBinderFloatUnityEventBinderIntUnityEventBinderLongUnityEventBinderStringUnityEventBinderPoseUnityEventBinderQuaternionUnityEventBinderVector2UnityEventBinderVector3UnityEventBinder
How to Use Typed Binders¶
The process is similar to the parameterless binder, but with a typed UnityEvent:
-
Add a Typed Binder: A specific typed binder is added to a
GameObject(e.g.,Vector3UnityEventBinder). -
Assign the Typed GameEvent: A corresponding typed
GameEvent<T>asset is assigned (e.g., aVector3Variable, asVariable<T>derived fromGameEvent<T>). -
Configure the Typed UnityEvent: The Inspector will show a
On Typed Game Event Raised (T)event (e.g.,On Typed Game Event Raised (Vector3)). This is aUnityEvent<T>that can pass the event's data payload directly to the listening methods. Methods that accept a parameter of the corresponding type can be selected.For example, a Transform's
localPositioncan be linked directly to aVector3UnityEventBinder'sUnityEvent.
Special Binders¶
-
BoolUnityEventBinder: In addition to the standardUnityEvent<bool>, this binder also provides anOn Negated Bool Event Raisedevent that is invoked with the opposite boolean value.
-
StringUnityEventBinder: This binder has a special behavior where it can also be used with a parameterlessGameEvent. In this case, it will invoke theUnityEvent<string>with theToString()representation of theGameEventobject itself.
-
UnityEventBatchBinder: This component allows you to listen to multipleGameEvents and invoke a singleUnityEventin response. This is useful when you have multiple events that should trigger the same response.
Creating Custom UnityEventBinder<T>¶
A custom typed UnityEventBinder can be created as necessary:
-
Define the Custom Data Type and
GameEvent<T>: A[Serializable]data type and a correspondingGameEvent<T>class for it must be defined.// File: PlayerData.cs using System; [Serializable] public struct PlayerData { public string name; public int level; } // File: PlayerDataGameEvent.cs using Soar.Events; using UnityEngine; [CreateAssetMenu(fileName = "PlayerDataGameEvent", menuName = "SOAR/Game Events/Player Data GameEvent")] public class PlayerDataGameEvent : GameEvent<PlayerData> { } -
Create the Custom Binder Class: A new class that inherits from
UnityEventBinder<T>is created, specifying the custom type.
The UnityEventBinder<T> base class handles all the logic. The PlayerDataUnityEventBinder component can now be added to a GameObject and used to listen for PlayerDataGameEvents.
Lifecycle¶
The UnityEventBinder automatically handles subscribing to the GameEvent in its Start() method and unsubscribing in its OnDestroy() method. This ensures that there are no memory leaks from lingering subscriptions when the GameObject is destroyed.
Sample Usage¶
To test this feature, the relevant sample package can be imported from the Package Manager window.

The UnityEventBinder Sample demonstrates how a UnityEventBinder can listen for a GameEvent and trigger a UnityEvent in response, all configured in the Inspector. This allows for codeless wiring of events to component methods.
For detailed setup and usage instructions, please refer to the README.md file inside the UnityEventBinderSamples folder after importing.