During system design discussions at the start of a project, a familiar question almost always comes up: "Where should we store enemy stats and equipment data? Directly on the Prefab, exported as JSON files, or inside ScriptableObjects?"
On the surface, this sounds like a straightforward tool-selection problem: list the pros and cons of each option, pick one standard for the project, and move on.
However, across projects ranging from two-week prototypes to multi-year live-ops titles, I have found that this question hides a subtle architectural trap. The trap lies in the unspoken assumption that Prefab, JSON, and ScriptableObject sit on the same horizontal plane as mutually exclusive substitutes.
Under the hood of the Unity Engine, these three concepts belong to three completely different architectural layers. Forcing one layer to do the job of another inevitably creates bottlenecks in memory allocation, asset loading dependencies, or live-ops deployment workflows.
1. Separating the Architectural Layers: Three Tools, Three Distinct Roles
Before deciding when to use each tool, we need to place Prefab, ScriptableObject, and JSON in their rightful layers within a Unity project's architecture.
flowchart LR
T1["LAYER 1: OUTSIDE PIPELINE\nJSON / Binary Payload\n- Lives outside standalone build\n- Network transport & Save Game"]
T2["LAYER 2: INSIDE PIPELINE\nScriptableObject\n- Static Editor asset data\n- Preserves GUID & shares RAM"]
T3["LAYER 3: IN ACTIVE SCENE\nPrefab Template\n- GameObject scene entity\n- Transform, Mesh, Animator"]
T1 -->|"1. Ingest data / Live patch"| T2
T2 -->|"2. Supply config & Asset link"| T3
Looking at this three-tier stack from top to bottom, the fundamental difference is not syntax or file format, but where each tool lives relative to Unity's Asset Pipeline and the Scene lifecycle:
-
Layer 1 (
JSON): Lives outside Unity's Asset Pipeline, dedicated to network data transport and local disk persistence. -
Layer 2 (
ScriptableObject): Lives inside Unity's Asset Pipeline, holding baseline configurations and GUID-backed asset links in the Editor. -
Layer 3 (
Prefab): Lives in the Scene presentation layer, acting as the visual entity that receives data from the upper layers to render meshes, physics, and animations.
2. Under the Hood: Technical Mechanics and Operational Costs
2.1. Prefabs: Serialized GameObject Templates, Not Data Containers
At its core, a Prefab is a serialized template of a GameObject hierarchy and its attached components (Transform, MeshRenderer, Animator, Collider, and MonoBehaviour). Its primary responsibility is instantiating visual and physical entities inside a Scene.
When we embed balance stats (maxHp, attackDamage, moveSpeed, goldReward) directly into [SerializeField] fields on a Prefab's MonoBehaviour and treat that as our primary data store, we tightly couple Static Data with View Hierarchy and GameObject Lifecycle. As a project scales, this creates three concrete engineering problems:
-
Redundant Managed Heap Allocations on Instantiation: Calling
Object.Instantiate(prefab)to spawn 100 identical enemies not only creates 100 C++ Native entities, but also allocates 100MonoBehaviourinstances on the C# Managed Heap and copies everymaxHp,attackDamage, andmoveSpeedfield into each individual instance - even though those baseline configuration numbers are identical. -
Heavy Asset Dependency Chains: Suppose you build a Bestiary or Shop UI in the main lobby that only needs to read the names and
attackDamageof 50 bosses to render text. If those numbers live insideMonoBehaviourcomponents attached to 50 bossPrefabassets, loading thosePrefabassets just to read a few integers forces Unity to pull their entire dependency tree (Meshassets, high-resolutionTexturemaps,Materialshaders,AnimationClipdata, andAudioClipbuffers) into RAM before the player even enters combat. -
Git Merge Conflicts and Fragile Workflows: Configuration numbers get buried inside
.prefabYAML files alongside visual hierarchy data. Every time a Game Designer opens aPrefabto tweak health points, they touch the exact same YAML file that Artists or VFX Engineers are modifying for particle systems or bone rigging.
2.2. JSON: Flexible Distribution, Blind to the Asset Pipeline
A common argument against JSON is that "designers might make syntax typos with commas or brackets." In a professional production pipeline, that argument rarely holds weight. Nobody writes raw JSON by hand in Notepad; data is exported from spreadsheets or CMS tools with automated schema validation and parsed via JsonUtility or Newtonsoft.Json.
The real engineering trade-offs of JSON lie deeper:
-
Complete Isolation from Unity's Asset Pipeline:
JSONis a text-based data transport format. It understands strings, numbers, booleans, arrays, and objects, but has zero awareness of Unity'sSprite,Prefab,AudioClip, orAnimationCurvetypes. You cannot hold a direct reference to a weapon icon inside JSON; you can only store a string identifier like"iconAddress": "Icons/Weapons/Sword_Flame"and build a runtime asset resolution layer usingAddressables. If someone renames or moves an asset in the Project window without updating the string table, the broken link only surfaces at runtime when a player opens that specific inventory slot. -
Parsing Overhead and Managed Heap Allocations: Reading a large JSON payload and deserializing it into C# objects at startup requires scanning strings and allocating intermediate buffers on the C# Managed Heap, adding pressure to the Garbage Collector (
GC.Alloc) if not carefully managed.
In exchange for those costs, JSON excels where compiled engine assets struggle: living completely outside the client build lifecycle. A lightweight JSON payload can be fetched from a CDN at launch to hot-patch game balance, adjust event drop rates, or persist player progression (Save Game) to Application.persistentDataPath.
2.3. ScriptableObjects: Native Data Assets and the Truth About Remote Updates
ScriptableObject takes the opposite approach from JSON. Inheriting directly from UnityEngine.Object, it is a first-class citizen of Unity's native serialization system without needing to be attached to any GameObject in a Scene.
Because it lives inside Unity's Asset Pipeline, ScriptableObject solves the structural weaknesses of both Prefab and JSON:
-
GUID-Backed Asset Links: Dragging a
Sprite,AudioClip, orAnimationCurveinto aScriptableObjectstores the reference via Unity'sGUIDandFileIDsystem. Renaming or moving files inside the Project window never breaks the reference. -
Flyweight Memory Sharing: Whether 10 or 500 enemy instances are active in a Scene, they all hold an 8-byte pointer (on 64-bit architectures) referencing a single
ScriptableObjectinstance in memory. -
Immediate Editor Validation: Paired with
OnValidate(), out-of-bounds numbers or missing references are caught and clamped immediately inside the Inspector.
However, there is a widespread misconception: "Using ScriptableObjects means you cannot update balance numbers remotely without rebuilding the entire client app."
Looking closely at Unity's architecture, that statement is only half true:
-
What CAN Be Updated Remotely - Field Values: If you pack your
ScriptableObject.assetfiles into remote Addressables AssetBundles hosted on a CDN, tweakingmaxHpfrom1000to1500or swapping aSpritereference and rebuilding the Addressables bundle allows client devices to download the updated values at runtime without recompiling or resubmitting an APK or IPA build. -
What CANNOT Be Updated Remotely - The C# Schema: What is permanently baked into the player build is the compiled C# class definition of that
ScriptableObjectinsidelibil2cpp.soor the iOS binary. You can remotely update the values of existing serialized fields via Addressables, but if you want to dynamically patch a subset of numbers across platforms without rebuilding platform-specific AssetBundles, a few kilobytes ofJSONfrom a remote config endpoint is much faster and lighter to deploy.
Furthermore, in standalone player builds, runtime mutations to a ScriptableObject in memory are never automatically written back to disk. Using ScriptableObject directly as a runtime Save Game persistence format is a misuse of the tool.
3. Combining All Three in Production: The Hybrid Data Pipeline
To demonstrate how these three tools complement each other in an enterprise game architecture, consider designing the data pipeline for a mobile Auto-Battler or Hero Collector (in the style of Teamfight Tactics or Clash Royale). The game features a roster of over 100 playable units, each demanding numerical combat balancing (health pools, damage values, attack cadence), lightweight 2D assets (avatar icons, portrait cards), and heavy 3D assets (character Prefabs, skeletal rigs, Animator controllers, and complex VFX).
The core operational challenge surfaces during live operations: The design team must push weekly balance patches over the air via a minified JSON payload without forcing players to re-download multi-gigabyte AssetBundles. Furthermore, when players browse the hero gallery or deck builder in the lobby, the UI must only load numerical stats and 2D sprites - strictly avoiding loading 3D meshes into RAM to prevent out-of-memory crashes on entry-level mobile devices. Finally, during active matches, the 3D Prefab acts strictly as a presentation View, ingesting an immutable merged data object without polluting the source .asset in memory.
Once we recognize that each tool belongs to a distinct architectural layer, the solution is no longer "pick one and discard the others," but orchestrating all three through explicit custom classes (which we will write in the code sample below):
-
ScriptableObjectOwns Baseline Data and Lightweight Asset References (ourUnitStaticConfigSOclass): Stores baseline combat stats, directSpritereferences for UI display, and a stringPrefabAssetGuid(orAssetReference) instead of a hardGameObjectreference to the heavy 3DPrefab- preventing the Bestiary/Shop UI from pulling 3D meshes and animations into RAM just to display stats. -
JSONActs as a Lightweight Live-Ops Override Patch (ourUnitLiveBalancePatchDtoclass): When designers need to hot-fix boss health or event damage in production without rebuilding AssetBundles, the server delivers a compact JSON patch deserialized intoUnitLiveBalancePatchDtokeyed byunitId. -
Pure C# Runtime Merger (
UnitConfigResolverandResolvedUnitConfig): To avoid mutating the originalScriptableObjectin memory, we write a custom pure C# class namedUnitConfigResolverthat mergesUnitStaticConfigSOandUnitLiveBalancePatchDto, validates bounds, and outputs an immutableResolvedUnitConfiginstance implementingIUnitEffectiveConfig. -
PrefabRemains a Pure Scene View Template (ourUnitPrefabViewBridgecomponent): Attached to the Prefab, it contains only rendering, animation, and physics components, receiving the final mergedIUnitEffectiveConfigat runtime:
flowchart TD
SO["UnitStaticConfigSO - Layer 2\nBaseline Stats + Icon Sprite + PrefabAssetGuid"]
Patch["UnitLiveBalancePatchDto - Layer 1\nLive-Ops JSON Override Patch from Server"]
Resolver["UnitConfigResolver - Custom C# Class\nValidates bounds and merges config safely"]
Resolved["ResolvedUnitConfig\nImmutable merged configuration"]
View["UnitPrefabViewBridge - Layer 3\nMonoBehaviour on Prefab receiving final data"]
SO -->|"1. Baseline config"| Resolver
Patch -->|"2. Event stat overrides"| Resolver
Resolver -->|"3. Creates immutable record"| Resolved
Resolved -->|"4. Injected into Prefab"| View
using System;
using UnityEngine;
using NUnit.Framework;
// 1. Read-only contract providing merged configuration data to Gameplay and Prefab Views
public interface IUnitEffectiveConfig
{
string UnitId { get; }
int MaxHp { get; }
float AttackDamage { get; }
float AttackInterval { get; }
string PrefabAssetGuid { get; }
}
// 2. Pure C# serializable data wrapped inside ScriptableObject for clean unit testing and sanitization
[Serializable]
public class UnitStaticData : IUnitEffectiveConfig
{
[SerializeField] private string unitId = "boss_iron_golem";
[SerializeField, Min(1)] private int maxHp = 2000;
[SerializeField, Min(0f)] private float attackDamage = 150f;
[SerializeField, Min(0.1f)] private float attackInterval = 1.5f;
[SerializeField] private string prefabAssetGuid = "guid_prefab_iron_golem_01";
public string UnitId => unitId;
public int MaxHp => maxHp;
public float AttackDamage => attackDamage;
public float AttackInterval => attackInterval;
public string PrefabAssetGuid => prefabAssetGuid;
public UnitStaticData() { }
public UnitStaticData(string id, int hp, float damage, float interval, string assetGuid)
{
unitId = id;
maxHp = hp;
attackDamage = damage;
attackInterval = interval;
prefabAssetGuid = assetGuid;
Sanitize();
}
public void Sanitize()
{
if (string.IsNullOrWhiteSpace(unitId))
{
unitId = "default_unit";
}
maxHp = Math.Max(1, maxHp);
attackDamage = Math.Max(0f, attackDamage);
attackInterval = Math.Max(0.1f, attackInterval);
prefabAssetGuid ??= string.Empty;
}
}
// 3. ScriptableObject Layer: Stores baseline config in the Editor and links to the Asset Pipeline.
// Avoids holding a hard GameObject reference to the heavy 3D Prefab so loading this SO in a UI screen
// does not pull 3D Meshes/Animations into RAM; uses PrefabAssetGuid (or AssetReference) instead.
[CreateAssetMenu(fileName = "UnitStaticConfig", menuName = "GameConfig/Unit Static Config")]
public class UnitStaticConfigSO : ScriptableObject, IUnitEffectiveConfig
{
[SerializeField] private UnitStaticData data = new UnitStaticData();
[SerializeField] private Sprite unitIconReference;
public string UnitId => data.UnitId;
public int MaxHp => data.MaxHp;
public float AttackDamage => data.AttackDamage;
public float AttackInterval => data.AttackInterval;
public string PrefabAssetGuid => data.PrefabAssetGuid;
public Sprite UnitIconReference => unitIconReference;
private void OnValidate()
{
data?.Sanitize();
}
}
// 4. JSON Transport Layer: DTO for hot-balance overrides parsed via JsonUtility or Newtonsoft.Json.
// Note: Unity's C++ JsonUtility does not support Nullable<T> (int?, float?), so explicit bool flags are used.
[Serializable]
public class UnitLiveBalancePatchDto
{
public string unitId;
public bool hasMaxHpOverride;
public int maxHpOverride;
public bool hasAttackDamageOverride;
public float attackDamageOverride;
public float attackIntervalMultiplier = 1f;
}
// 5. Immutable runtime configuration object produced after merging ScriptableObject baseline with JSON patch
public sealed class ResolvedUnitConfig : IUnitEffectiveConfig
{
public string UnitId { get; }
public int MaxHp { get; }
public float AttackDamage { get; }
public float AttackInterval { get; }
public string PrefabAssetGuid { get; }
public float EffectiveDps => AttackDamage / AttackInterval;
public ResolvedUnitConfig(string unitId, int maxHp, float attackDamage, float attackInterval, string prefabAssetGuid)
{
UnitId = unitId;
MaxHp = Math.Max(1, maxHp);
AttackDamage = Math.Max(0f, attackDamage);
AttackInterval = Math.Max(0.1f, attackInterval);
PrefabAssetGuid = prefabAssetGuid ?? string.Empty;
}
}
// 6. Configuration Resolver: Merges ScriptableObject baseline with JSON live-ops patch safely
public static class UnitConfigResolver
{
public static ResolvedUnitConfig Resolve(IUnitEffectiveConfig baseConfig, UnitLiveBalancePatchDto patch)
{
if (baseConfig == null)
{
throw new ArgumentNullException(nameof(baseConfig));
}
if (patch == null || !string.Equals(patch.unitId, baseConfig.UnitId, StringComparison.Ordinal))
{
return new ResolvedUnitConfig(
baseConfig.UnitId,
baseConfig.MaxHp,
baseConfig.AttackDamage,
baseConfig.AttackInterval,
baseConfig.PrefabAssetGuid
);
}
int finalMaxHp = patch.hasMaxHpOverride ? patch.maxHpOverride : baseConfig.MaxHp;
float finalDamage = patch.hasAttackDamageOverride ? patch.attackDamageOverride : baseConfig.AttackDamage;
float safeMultiplier = patch.attackIntervalMultiplier > 0f ? patch.attackIntervalMultiplier : 1f;
float finalInterval = baseConfig.AttackInterval * safeMultiplier;
return new ResolvedUnitConfig(
baseConfig.UnitId,
finalMaxHp,
finalDamage,
finalInterval,
baseConfig.PrefabAssetGuid
);
}
}
// 7. Prefab View Layer: MonoBehaviour attached to the Prefab only receives resolved config to operate
public class UnitPrefabViewBridge : MonoBehaviour
{
[SerializeField] private UnitStaticConfigSO baselineConfig;
public ResolvedUnitConfig ActiveConfig { get; private set; }
public int CurrentHp { get; private set; }
public void InitializeWithPatch(UnitLiveBalancePatchDto livePatch)
{
if (baselineConfig == null)
{
Debug.LogError("Missing UnitStaticConfigSO on " + gameObject.name);
enabled = false;
return;
}
ActiveConfig = UnitConfigResolver.Resolve(baselineConfig, livePatch);
CurrentHp = ActiveConfig.MaxHp;
}
}
[TestFixture]
public class HybridDataPipelineTests
{
[Test]
public void Resolve_WithoutJsonPatch_PreservesScriptableObjectBaseline()
{
var baseConfig = new UnitStaticData(
id: "boss_iron_golem",
hp: 2000,
damage: 150f,
interval: 1.5f,
assetGuid: "guid_prefab_iron_golem_01");
ResolvedUnitConfig resolved = UnitConfigResolver.Resolve(baseConfig, null);
Assert.AreEqual(2000, resolved.MaxHp);
Assert.AreEqual(100f, resolved.EffectiveDps);
Assert.AreEqual("guid_prefab_iron_golem_01", resolved.PrefabAssetGuid);
}
[Test]
public void Resolve_WithLiveOpsJsonPatch_OverridesStatsAndClampsInvalidValues()
{
var baseConfig = new UnitStaticData(
id: "boss_iron_golem",
hp: 2000,
damage: 150f,
interval: 1.5f,
assetGuid: "guid_prefab_iron_golem_01");
// Simulates a DTO parsed from a Remote Config JSON payload during a weekend live-ops event
var livePatch = new UnitLiveBalancePatchDto
{
unitId = "boss_iron_golem",
hasMaxHpOverride = true,
maxHpOverride = 3500,
hasAttackDamageOverride = true,
attackDamageOverride = -999f,
attackIntervalMultiplier = 0.5f
};
ResolvedUnitConfig resolved = UnitConfigResolver.Resolve(baseConfig, livePatch);
// MaxHp updates to 3500 from the JSON patch, negative damage is safely clamped to 0,
// attack interval is halved (1.5s * 0.5 = 0.75s), and the original asset GUID remains intact
Assert.AreEqual(3500, resolved.MaxHp);
Assert.AreEqual(0f, resolved.AttackDamage);
Assert.AreEqual(0.75f, resolved.AttackInterval);
Assert.AreEqual("guid_prefab_iron_golem_01", resolved.PrefabAssetGuid);
// Baseline ScriptableObject data remains completely unmutated after applying the patch
Assert.AreEqual(2000, baseConfig.MaxHp);
Assert.AreEqual(150f, baseConfig.AttackDamage);
}
}
4. Architectural Trade-Off Matrix Across the Three Layers
| Technical Criterion | Prefab | ScriptableObject | JSON |
|---|---|---|---|
| Core Architectural Role | Scene entity template containing View, Hierarchy, Physics, and Animation | Native static data asset integrated into Unity's Asset Pipeline | External data transport, remote configuration patch, and player save format |
| Memory Allocation Behavior | Duplicates serialized C# fields on the Managed Heap for every Instantiate() call |
Shares a single Flyweight instance in RAM across hundreds of scene entities | Allocates strings and temporary objects on the Managed Heap during parsing |
| Asset Links (Sprite, Prefab, Audio) | Maintains direct GUID-backed references via Unity Serializer | Maintains direct GUID-backed references via Unity Serializer | Cannot hold direct asset references; requires string keys and runtime resolution |
| Remote Hot-Updating Without App Rebuild | Requires rebuilding and downloading heavy Addressables bundles |
Can update field values via remote Addressables, but C# schema is fixed in IL2CPP |
Extremely agile; fetches lightweight text payloads from any CDN or REST API |
| Player Save Game Persistence | Unsuitable | Unsuitable; runtime mutations do not persist to disk in player builds | Industry standard for reading/writing to Application.persistentDataPath or cloud storage |
5. Practical Takeaways
When designing a data architecture in Unity, instead of asking "Should we pick Prefabs, JSON, or ScriptableObjects?", a more productive engineering question is: "Which architectural layer does this data belong to, and what is its operational cost across the project's lifecycle?"
- Let Prefabs do the job of visual and physical templates in the Scene rather than acting as spreadsheets for combat balance.
- Use ScriptableObjects as the backbone for static configuration in the Editor, where Inspector ergonomics, Flyweight memory sharing, and GUID-backed asset links shine.
- Combine JSON (or a binary equivalent) whenever data needs to cross the boundary of the compiled build: saving player progress, syncing with backend servers, delivering lightweight live-ops balance overrides, or importing spreadsheet tables into
ScriptableObjectassets via Editor tooling.

Top comments (0)