Skip to content

RuntimeScriptableObject Class

Base class for UnityEngine.ScriptableObject that have values that should be resettable.

C#
[HelpURL("https://hertzole.github.io/scriptable-values/guides/creating-custom-types")]
public abstract class RuntimeScriptableObject : ScriptableObject, INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider

Inheritance object → UnityEngine.Object → UnityEngine.ScriptableObject

Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider

Invoke the PropertyChanging event with the given property name.

C#
protected void NotifyPropertyChanging(string propertyName = "")

propertyName string
The name of the property that is changing.

NotifyPropertyChanging(PropertyChangingEventArgs)

Section titled “NotifyPropertyChanging(PropertyChangingEventArgs)”

Invokes the PropertyChanging event with the given PropertyChangingEventArgs.

C#
protected void NotifyPropertyChanging(PropertyChangingEventArgs args)

args PropertyChangingEventArgs
The to use.

Invoke the PropertyChanged event and the INotifyBindablePropertyChanged.propertyChanged event with the given property name.

C#
protected void NotifyPropertyChanged(string propertyName = "")

propertyName string
The name of the property that has changed.

NotifyPropertyChanged(PropertyChangedEventArgs)

Section titled “NotifyPropertyChanged(PropertyChangedEventArgs)”

Invoke the PropertyChanged event and the INotifyBindablePropertyChanged.propertyChanged event with the given PropertyChangedEventArgs.

C#
protected void NotifyPropertyChanged(PropertyChangedEventArgs args)

args PropertyChangedEventArgs
The to use.

Sets a field to a new value and notifies the property changed event.

C#
protected bool SetField<T>(ref T field, T newValue, string propertyName = "")

field T
The field to set.

newValue T
The new value to set.

propertyName string
The name of the property that is changing.

bool
true if the field was changed; otherwise, false.

Calling this will not notify any property changes if the new value is the same as the current field value.

SetField(ref T, T, PropertyChangingEventArgs, PropertyChangedEventArgs)

Section titled “SetField(ref T, T, PropertyChangingEventArgs, PropertyChangedEventArgs)”

Sets a field to a new value and notifies the property changed event.

C#
protected bool SetField<T>(ref T field, T newValue, PropertyChangingEventArgs changingArgs, PropertyChangedEventArgs changedArgs)

field T
The field to set.

newValue T
The new value to set.

changingArgs PropertyChangingEventArgs
The to use.

changedArgs PropertyChangedEventArgs
The to use.

bool
true if the field was changed; otherwise, false.

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

C#
[Conditional("DEBUG")]
protected virtual void WarnIfLeftOverSubscribers()

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

Adds a stack trace.

C#
[Conditional("UNITY_EDITOR")]
protected void AddStackTrace(int skipFrames = 0)

skipFrames int
How many frames/calls to skip.

This only does something in the Unity editor. This method is completely blank in builds.

Removes all stack traces.

C#
[Conditional("UNITY_EDITOR")]
protected void ResetStackTraces()

This only does something in the Unity editor. This method is completely blank in builds.

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 virtual void OnPreStart()

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

Called when the game starts, after OnPreStart().

You should not prepare the object in this method! Use OnPreStart() instead.

C#
protected virtual void OnStart()

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

Called when the game is ending, before OnDisabled().

You should not clean up the object in this method! Use OnDisabled() instead.

C#
protected virtual void OnPreDisabled()

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

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 virtual void OnDisabled()

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

Called when the game exits play mode.

C#
[Obsolete("Use either 'OnPreDisabled' or 'OnDisabled' instead.")]
[ExcludeFromCodeCoverage]
protected virtual void OnExitPlayMode()