npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cz.xprees.variables

v1.0.25

Published

This package contains a system for creating variables based on ScriptableObjects in Editor.

Readme

Unity Variables Package - cz.xprees.variables

NPM Version

ScriptableObject-based variable architecture for decoupled state management, event observation, and multi-scene data sharing in Unity.

Features

  • ScriptableObject Variables - Store and share state without coupling systems together.
    • Extend VariableBaseSO<T> to author custom typed variables.
    • Observe runtime changes via the onValueChanged event.
  • Standalone Default State - Every variable manages its own authored defaultValue and deep-clones it into currentValue on OnEnable() and ResetToDefault().
  • PlayMode Transition Resets - Declarative [ResetOnPlayMode] attribute controls automatic reset when entering or exiting Play Mode.
  • State Lifetime Control - Inherits DescriptionBaseSO.lifetime (Scenario, Session, Persistent) for boundary-aware resets.
  • Persistent Variables - PersistentVariableBaseSO<T> backs a variable with PlayerPrefs so its value survives across sessions.
  • References - Inspector-switchable references (ReferenceBase<T>) supporting both inlined values and shared variable assets.
  • Variable Modifiers & Aggregations - Compose and transform variable streams dynamically.

Installation

Install the package using npm scoped registry in Project Settings > Package Manager > Scoped Registries:

{
    "name": "NPM - xprees",
    "url": "https://registry.npmjs.org",
    "scopes": [
        "cz.xprees",
        "com.dbrizov.naughtyattributes"
    ]
}

Then install cz.xprees.variables via the Unity Package Manager.


State Lifecycle & PlayMode Reset (DX)

Variables are completely self-contained and integrate with the centralized StateSnapshotService without requiring bespoke registration systems.

1. Default Behavior

By default, VariableBaseSO<T>:

  1. Clones defaultValue into currentValue on OnEnable().
  2. Automatically resets to default on entering Play Mode via [ResetOnPlayMode(PlayModeResetTiming.EnterPlayMode)].
  3. In Unity Editor, captures its baseline snapshot before the first runtime mutation via StateSnapshotService.EnsureCaptured(this).
  4. Reverts cleanly to baseline upon exiting Play Mode without dirtying asset files on disk.

2. Customizing PlayMode Resets via [ResetOnPlayMode]

Use [ResetOnPlayMode] to customize when custom variable classes reset:

using Xprees.Core;
using Xprees.Variables.Base;

// 1. Default: resets on Play Mode entry
public class AmmoVariable : IntVariable { }

// 2. Prevent Play Mode reset (e.g. for persistent editor values or external saves)
[ResetOnPlayMode(PlayModeResetTiming.None)]
public class PlayerProfileVariable : StringVariable { }

// 3. Reset on both entry and exit
[ResetOnPlayMode(PlayModeResetTiming.Both)]
public class TransientDebugFlagVariable : BoolVariable { }

3. Setting State Lifetime per Variable

Every variable ScriptableObject exposes the Lifetime dropdown in the Inspector (inherited from DescriptionBaseSO):

  • Scenario (Default): Resets automatically whenever a scenario starts or restarts via ScenarioStateRegistrySO and StateSnapshotService.RestoreAll().
  • Session: Persists across scenarios, resetting only when returning to the Main Menu or quitting.
  • Persistent: Never reset by scenario resets or Play Mode entry (e.g. Audio volume, resolution settings).
// You can also enforce class-level lifetime via attribute:
[StatefulLifetime(StateLifetime.Persistent)]
public class MasterVolumeVariable : FloatVariable { }

Persistent Variables (PlayerPrefs)

PersistentVariableBaseSO<T> stores its value in PlayerPrefs instead of keeping it purely in memory. It is declared [StatefulLifetime(StateLifetime.Persistent)] and [ResetOnPlayMode(PlayModeResetTiming.None)], so it is skipped by both the scenario snapshot restore and the Play Mode reset, and loads from PlayerPrefs on OnEnable() instead of cloning defaultValue.

Ready-made asset types live under Assets > Create > Variables/Persistent:

| Type | Backing store | |----------------------------|-------------------------------| | PersistentBoolVariable | PlayerPrefs int (0 / 1) | | PersistentIntVariable | PlayerPrefs int | | PersistentFloatVariable | PlayerPrefs float | | PersistentStringVariable | PlayerPrefs string |

Key points:

  • playerPrefsKey is required. There is no implicit key - an empty key logs an error and the value is not stored.
  • Write-through. Every CurrentValue set writes to PlayerPrefs before onValueChanged fires. Unity flushes to disk on quit and focus loss; call Flush() when an immediate write is required.
  • defaultValue is the fallback used when the key is not present yet. ResetToDefault() also overwrites the stored value, while ClearStoredValue() deletes the key.
  • Other types can extend PersistentJsonVariableSO<T>, which stores JsonUtility JSON in a string key. JsonUtility only round-trips [Serializable] classes and structs - top level primitives, enums and arrays need their own PersistentVariableBaseSO<T> subclass.
  • The inherited Lifetime dropdown is inert on these assets, because the class-level [StatefulLifetime] attribute takes precedence.