ScriptableEvent<T> Class
Definition
Section titled “Definition”A UnityEngine.ScriptableObject that can be invoked to trigger an event with an argument.
[HelpURL("https://hertzole.github.io/scriptable-values/types/scriptable-event")]public abstract class ScriptableEvent<T> : RuntimeScriptableObject, INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProviderType Parameters
Section titled “Type Parameters”T
The type of the argument.
Inheritance object → UnityEngine.Object → UnityEngine.ScriptableObject → RuntimeScriptableObject
Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider
Properties
Section titled “Properties”PreviousArgs
Section titled “PreviousArgs”The arguments that was passed to the event when it was invoked.
[CreateProperty]public T? PreviousArgs { get; }Methods
Section titled “Methods”Invoke(T)
Section titled “Invoke(T)”Invokes the event with the specified argument and this ScriptableEvent<T> as the sender.
public void Invoke(T args)Parameters
Section titled “Parameters”args T
The argument to send with the event.
Invoke(object, T)
Section titled “Invoke(object, T)”Invokes the event with the specified sender and argument.
public void Invoke(object sender, T args)Parameters
Section titled “Parameters”sender object
The object that invoked the event.
args T
The argument to send with the event.
OnBeforeInvoked(object, T)
Section titled “OnBeforeInvoked(object, T)”Called before the event is invoked. This can be used to prevent the event from being invoked.
protected virtual bool OnBeforeInvoked(object sender, T args)Parameters
Section titled “Parameters”sender object
The object that invoked the event.
args T
The argument that was passed to the event.
Returns
Section titled “Returns”bool
true if the event should be invoked; otherwise, false.
OnAfterInvoked(object, T)
Section titled “OnAfterInvoked(object, T)”Called after the event has been invoked.
protected virtual void OnAfterInvoked(object sender, T args)Parameters
Section titled “Parameters”sender object
The object that invoked the event.
args T
The argument that was passed to 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<T>? OnInvoked