Class ScyllaEventSubscription
A disposable token that represents an active subscription to a specific event type in the Scylla Event eXchange System (SEX).
Implements
Inherited Members
Namespace: Scylla.Core.Events
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaEventSubscription : IDisposable
Remarks
Every call to Listen<TEvent>(object, Action<TEvent>, ScyllaEventPriority) or the convenience wrapper Listen<TEvent>(object, Action<TEvent>, ScyllaEventPriority) returns a ScyllaEventSubscription. The subscription remains active until one of the following occurs:
-
Dispose() is called explicitly (or via a
usingblock). -
The subscriber object passed to
Listenis destroyed (Unity objects are checked via Unity's special null semantics; plain C# objects via reference equality).
Holding onto a subscription token and calling Dispose() when the
owning object is cleaned up (e.g., in OnDestroy for MonoBehaviours) is
the recommended pattern for explicit lifecycle control.
Subscribing and unsubscribing with an explicit token:
private ScyllaEventSubscription _subscription;
private void OnEnable()
{
_subscription = ScyllaEvents.Listen<PlayerDiedEvent>(this, OnPlayerDied);
}
private void OnDisable()
{
_subscription?.Dispose();
_subscription = null;
}
private void OnPlayerDied(PlayerDiedEvent e)
{
Debug.Log($"Player {e.PlayerName} died.");
}
Alternatively, subscriptions can be managed with a using block for
short-lived scopes:
Using a using block for a temporary subscription:
using (ScyllaEvents.Listen<PlayerDiedEvent>(this, OnPlayerDied))
{
// Subscription is active only within this block.
RunGameSequence();
}
Methods
Dispose()
Removes the associated event handler from the event bus, permanently cancelling this subscription.
Declaration
public void Dispose()
Remarks
This method is safe to call multiple times. After the first successful disposal, subsequent calls are silently ignored and the unsubscribe action is not invoked again.
Once disposed, the handler will no longer be invoked by any future Publish<TEvent>(TEvent) calls. Any currently in-progress dispatch that has already passed this handler is not affected.