Skip to content

ScriptableEvent<T> Class

A UnityEngine.ScriptableObject that can be invoked to trigger an event with an argument.

C#
[HelpURL("https://hertzole.github.io/scriptable-values/types/scriptable-event")]
public abstract class ScriptableEvent<T> : RuntimeScriptableObject, INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider

T
The type of the argument.

Inheritance object → UnityEngine.Object → UnityEngine.ScriptableObject → RuntimeScriptableObject

Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider

The arguments that was passed to the event when it was invoked.

C#
[CreateProperty]
public T? PreviousArgs { get; }

Invokes the event with the specified argument and this ScriptableEvent<T> as the sender.

C#
public void Invoke(T args)

args T
The argument to send with the event.

Invokes the event with the specified sender and argument.

C#
public void Invoke(object sender, T args)

sender object
The object that invoked the event.

args T
The argument to send with the event.

Called before the event is invoked. This can be used to prevent the event from being invoked.

C#
protected virtual bool OnBeforeInvoked(object sender, T args)

sender object
The object that invoked the event.

args T
The argument that was passed to the event.

bool
true if the event should be invoked; otherwise, false.

Called after the event has been invoked.

C#
protected virtual void OnAfterInvoked(object sender, T args)

sender object
The object that invoked the event.

args T
The argument that was passed to the event.

Called when the game starts, before OnStart().

You should not subscribe to events in this method! Use OnStart() instead. OnPreStart() should be used for preparing the scriptable object.

C#
protected override void OnPreStart()

If this isn’t called when the game starts, it’s called once this scriptable object is loaded and instantiated.

Warns if there are any left-over subscribers to the event.

C#
protected override void WarnIfLeftOverSubscribers()

This will only be called in the Unity editor and builds with the DEBUG flag.

Removes any subscribers from the event.

C#
public void ClearSubscribers(bool warnIfLeftOver = false)

warnIfLeftOver bool
If true, a warning will be printed in the console if there are any subscribers. The warning will only be printed in the editor and debug builds.

Called when the game is ending, after OnPreDisabled().

You should not unsubscribe from events in this method! Use OnPreDisabled() instead. OnDisabled() should be used for cleaning up the scriptable object.

C#
protected override void OnDisabled()

This can also be called during the game is the scriptable object is destroyed and/or unloaded.

Called when the event is invoked.

C#
public event EventHandler<T>? OnInvoked

EventHandler<T>