Get Your Personalized Game Dev Plan Tailored tips, tools, and next steps - just for you.

Scriptable Objects: Creating Dynamic Runtime Systems in Unity

Posted by Gemma Ellison
./
March 14, 2025
The cover for Scriptable Objects: Creating Dynamic Runtime Systems in Unity

Tired of juggling hundreds of game objects just to tweak a single stat? Scriptable Objects are your escape. They let you store shared data independently from script instances, leading to more modular and efficient code, especially when designing complex game systems. Effective use of Scriptable Objects is crucial for creating scalable and dynamic games in Unity.

Introduction to Scriptable Objects

What are Scriptable Objects? They are data containers that live outside of scenes and prefabs. Unlike MonoBehaviours, they don’t need to be attached to GameObjects.

Here’s why Scriptable Objects rock:

  • Data persistence: Scriptable Objects retain data between scene changes, eliminating the need to transfer data manually.
  • Reduced memory footprint: Data is shared, minimizing memory consumption.
  • Increased modularity: Code becomes more organized and reusable.

When should you use them? Consider Scriptable Objects for data that doesn’t need to be tied to a specific GameObject instance, such as game configurations, item definitions, or character stats.

A photograph of a minimalist painting featuring a single, thick, horizontal blue line against a stark white background

JSON or XML might be better for external data sources or very complex data structures.

Creating Scriptable Objects is easier than you think! Just use the CreateAssetMenu attribute.

Access them by referencing the created asset in the Unity Editor.

Now that you know the basics, let’s see how Scriptable Objects can store game data.

Storing Game Data with Scriptable Objects

First, define your game data structures. This structure allows for easy modification of item data without altering the core game logic.

Here’s an example:

[System.Serializable]
public class ItemData
{
    public string itemName;
    public int itemID;
    public string description;
    public Sprite icon;
}

[CreateAssetMenu(fileName = "NewItem", menuName = "Game Data/Item")]
public class Item : ScriptableObject
{
    public ItemData data;
}

Create Scriptable Object assets using the “Create” menu in the Unity Editor.

Organize assets with clear naming conventions (e.g., “Item_Sword_001”) and a logical folder structure (e.g., “Assets/Data/Items”).

Create a free account, or log in.

Gain access to free articles, game development tools, and game assets.