# Managed Scriptable Object

To understand the usage of this class, 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).

This class, `ManagedScriptableObject`, exposes a method called `Reset()` which will be invoked when exiting Play Mode, offering you a chance to reset the SO's state.

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.

***

## Using this class

### Inheriting from it

To use Managed Scriptable Object in your scripts, simply inherit from it and implement the `Reset()` method.

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 : ManagedScriptableObject
{
    public int score;

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

This way, even if no one sets the score to zero, upon exiting Play Mode the Reset method will be invoked.


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
