Skip to content

ScriptableEvent Class

A UnityEngine.ScriptableObject that can be invoked to trigger an event without any arguments.

C#
[CreateAssetMenu(fileName = "New Runtime Event", menuName = "Hertzole/Scriptable Values/Events/Runtime Event", order = -950)]
[HelpURL("https://hertzole.github.io/scriptable-values/types/scriptable-event")]
public class ScriptableEvent : RuntimeScriptableObject, INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider

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

Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider

C#
public static readonly PropertyChangedEventArgs previousArgsChanged
C#
public static readonly PropertyChangingEventArgs previousArgsChanging

Invokes the event with this ScriptableEvent as the sender.

C#
public void Invoke()

Invokes the event with the specified sender.

C#
public void Invoke(object sender)

sender object
The object that invoked 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)

sender object
The object that invoked 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)

sender object
The object that invoked 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? OnInvoked

EventHandler