ScriptableEvent Class
Definition
Section titled “Definition”A UnityEngine.ScriptableObject that can be invoked to trigger an event without any arguments.
[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, IStackTraceProviderInheritance object → UnityEngine.Object → UnityEngine.ScriptableObject → RuntimeScriptableObject
Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider
Fields
Section titled “Fields”previousArgsChanged
Section titled “previousArgsChanged”public static readonly PropertyChangedEventArgs previousArgsChangedpreviousArgsChanging
Section titled “previousArgsChanging”public static readonly PropertyChangingEventArgs previousArgsChangingMethods
Section titled “Methods”Invoke()
Section titled “Invoke()”Invokes the event with this ScriptableEvent as the sender.
public void Invoke()Invoke(object)
Section titled “Invoke(object)”Invokes the event with the specified sender.
public void Invoke(object sender)Parameters
Section titled “Parameters”sender object
The object that invoked the event.
OnBeforeInvoked(object)
Section titled “OnBeforeInvoked(object)”Called before the event is invoked. This can be used to prevent the event from being invoked.
protected virtual bool OnBeforeInvoked(object sender)Parameters
Section titled “Parameters”sender object
The object that invoked the event.
Returns
Section titled “Returns”bool
true if the event should be invoked; otherwise, false.
OnAfterInvoked(object)
Section titled “OnAfterInvoked(object)”Called after the event has been invoked.
protected virtual void OnAfterInvoked(object sender)Parameters
Section titled “Parameters”sender object
The object that invoked the event.
OnPreStart()
Section titled “OnPreStart()”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.
protected override void OnPreStart()Remarks
Section titled “Remarks”If this isn’t called when the game starts, it’s called once this scriptable object is loaded and instantiated.
WarnIfLeftOverSubscribers()
Section titled “WarnIfLeftOverSubscribers()”Warns if there are any left-over subscribers to the event.
protected override void WarnIfLeftOverSubscribers()Remarks
Section titled “Remarks”This will only be called in the Unity editor and builds with the DEBUG flag.
ClearSubscribers(bool)
Section titled “ClearSubscribers(bool)”Removes any subscribers from the event.
public void ClearSubscribers(bool warnIfLeftOver = false)Parameters
Section titled “Parameters”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.
OnDisabled()
Section titled “OnDisabled()”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.
protected override void OnDisabled()Remarks
Section titled “Remarks”This can also be called during the game is the scriptable object is destroyed and/or unloaded.
Events
Section titled “Events”OnInvoked
Section titled “OnInvoked”Called when the event is invoked.
public event EventHandler? OnInvoked