# Session State Values

{% hint style="success" %}

#### Like what your seeing?

Support us as a [GitHub Sponsor](/old-kb/where-to-buy/become-a-sponsor.md) and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude.\
\
These articles are made possible by our [GitHub Sponsors](/old-kb/where-to-buy/become-a-sponsor.md) ... become a sponsor today!
{% endhint %}

## Introduction

You can store simple primitive variables in the editors session state. These do not get wiped on code recompile and reload but are removed when the editor session is closed.

{% embed url="<https://docs.unity3d.com/ScriptReference/SessionState.html>" %}

These are important to use when your installing, updating or removing packages via script since any of those actions will cause a domain reload so all of your internal state data will be wiped... except of course the Session State Values.

What we do is set bools to know what we are doing and what we have done, in this way we insure we don't spam the user with a dialog or request every time the scripts compile. for example

***Pseudo Code***

```csharp
if(!SystemCoreIsInstalled
    && !SessionState.GetBool("SystemCoreHasAskedToInstall", false))
{
    SessionState.SetBool("SystemCoreHasAskedToInstall", true);
    AskToInstallSystemCore();
}
```

In the above example we check to see if we need to install System Core, and if we do and we have not already asked the user if we can ... then and only then do we ask the user.

This insures we never ask the user more than once per session.

```csharp
private IEnumerator InstallSystemCore()
{
    if(!SessionState.GetBool("SystemCoreInstalling", false))
    {
        SessionState.SetBool("SystemCoreInstalling", true);
        //Do Work
        SessionState.SetBool("SystemCoreInstalling", false);
    }
}
```

In this example we check if we are already installing System Core … if we are we do nothing … if we are not we indicate that we are now installing it by setting the SystemCoreInstalling value to true, then do our work, then set it back to false. In this way if another process trys to call Install System Core even if that is after a domain reload we will still not step on our own toes.


---

# 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://kb.heathen.group/old-kb/assets/tips-for-asset-developers/session-state-values.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.
