Unity editor utility for resetting ScriptableObject
state after changes made during editor play mode, mimicking scene object behavior.
Unlike scene MonoBehaviour
objects, ScriptableObject
instances are assets which persist changes made during editor play mode. This makes them less useful as stateful runtime data containers such as entities, singleton managers, or shared variables.
By aligning their behavior with scene objects, they can serve as stateful singletons shared across scenes and referenced through the inspector, simplifying cross-object communication.
- Unity 2019.2+
- In the Unity Editor, click Window → Package Manager.
- Click + (top left) → Install package from git URL….
- Enter this repository URL with the
.git
suffix:https://github.com/darksailstudio/resettables.git
- Download the latest release, or clone this repository.
- In the Unity Editor, click Window → Package Manager.
- Click + (top left) → Install package from disk….
- Select the
package.json
file.
Create a new ScriptableObject
derived class and mark it with ResetOnExitPlayMode
attribute:
using DarkSail.Resettables;
using UnityEngine;
[ResetOnExitPlayMode]
[CreateAssetMenu(menuName = "My Project/My Entity")]
class MyEntity : ScriptableObject
{
public int Value;
}
All derived classes will inherit the resetting behavior unless explicitly disabled:
using DarkSail.Resettables;
using UnityEngine;
[ResetOnExitPlayMode(Inherit = false)]
class Resettable : ScriptableObject
{
public int Value;
}
class NotResettable : Resettable { }