> For the complete documentation index, see [llms.txt](https://tools.continis.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tools.continis.io/scriptable-object-tools/utilities/managedscriptableobject.md).

# AutoReset classes

To understand the usage of these classes, it's important to understand Unity's Enter Play Mode Options and the effect that not reloading the domain can have on ScriptableObjects.

The lifetime of a ScriptableObject, unlike a GameObject in the scene, doesn't start and finish with Play Mode. An SO can call its `OnEnable()` only once when the editor is started (or when code recompiles), so its state is not cleared when entering Play Mode (like it happens to GameObjects and their scripts).

For more information, read all about Unity's [Enter Play Mode Options](https://docs.unity3d.com/Manual/ConfigurableEnterPlayMode.html) and especially [disabling Domain Reload](https://docs.unity3d.com/Manual/DomainReloading.html) on their documentation.

To deal with these complications, ScriptableObject Tools provides three base classes `AutoResetOnEnterPlayMode` `AutoResetOnExitPlayMode` and `AutoResetOnBoth`. They expose methods that will be invoked when entering or exiting Play Mode, offering you a chance to reset the SO's state.

***

## Using these classes

To use one of the AutoReset classes, simply inherit from them and implement the abstract methods contained within: `OnEnterPlayMode()`, `OnExitPlayMode()`, or both; depending on the class.

For instance, if you wanted to make an SO that holds the score of the game, you want to make sure to reset it when the editor exits Play Mode, like this:

```csharp
[CreateAssetMenu]
public class MySmartSO : AutoResetOnExitPlayMode
{
    public int score;

    public void AddPoints(int points) => score += points;
    
    protected override void OnExitPlayMode()
    {
        score = 0;
    }
}
```

This way, even if no code resets the score, upon exiting Play Mode the `OnExitPlayMode()` will take care of that.

{% hint style="warning" icon="triangle-exclamation" %}
These classes set up their listeners in `OnEnable()` and `OnDisable()`.

If you want to use those methods you have to declare them as `override` and invoke the base ones to make sure the listeners are correctly set up:

```csharp
public class MySmartSO : AutoResetOnExitPlayMode
{
    protected override void OnEnable()
    {
        base.OnEnable();
        // This class' OnEnable code...
    }
}
```

{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tools.continis.io/scriptable-object-tools/utilities/managedscriptableobject.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
