Course contentsShow
← Unity Game Development
Lesson 242 of 8284. Prefabs and Data ManagementFree lesson

Managing Global Game Settings via ScriptableObjects

Utilize a singleton-style ScriptableObject to store and access global game state settings across multiple independent scenes.

In this lesson, you will learn how to use a single, persistent ScriptableObject to act as a "source of truth" for game settings that need to be accessed consistently across multiple scenes.

The Global Data Pattern

In Unity, scenes are independent, meaning any local variables within a scene are destroyed when you switch to a new one. While MonoBehaviour singletons are a common way to solve this, they require complex DontDestroyOnLoad logic. Using a ScriptableObject is much cleaner: since it exists as an asset in your Project folder rather than an object in a specific scene, it remains loaded in memory regardless of which scene is currently active.

Implementing the Settings Asset

First, we create a container for our settings, such as audio levels or difficulty modifiers:

[CreateAssetMenu(fileName = "GameSettings", menuName = "Settings/GameSettings")]
public class GameSettings : ScriptableObject
{
    public float masterVolume = 1.0f;
    public bool isHardMode = false;
}

Once you create this asset in your Project window (Right-click > Create > Settings > GameSettings), you can drag and drop this single asset reference into any script in any scene.

Accessing the State

Because the ScriptableObject reference points to the exact same file in your project, every script referencing it sees the same values. If your "Settings Menu" script updates masterVolume, your "AudioManager" script—located in a completely different scene—will immediately see that updated value the next time it runs.

This approach eliminates the need for complex scene-to-scene data passing. You simply define the asset once, and your various systems—whether they reside in the Main Menu, the Gameplay Scene, or the Pause Menu—all point to the same data container. This ensures your global configuration remains perfectly synchronized, even as the player navigates through different parts of your game.

Key Takeaway: By storing global state in a ScriptableObject asset rather than a scene-bound object, you create a permanent, unified source of truth that is automatically accessible across all your game scenes.