0
0
Unityframework~8 mins

ScriptableObjects for game data in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: ScriptableObjects for game data
MEDIUM IMPACT
This concept affects runtime memory usage and load times by how game data is stored and accessed.
Storing shared game data like item stats or configuration
Unity
[CreateAssetMenu(fileName = "ItemData", menuName = "Game/ItemData")]
public class ItemData : ScriptableObject {
    public int damage;
    public float weight;
}

// Shared asset reused
public ItemData swordAsset;
public ItemData axeAsset;
Data is stored once as an asset and shared, reducing memory and load time.
📈 Performance GainSaves memory by sharing data; faster load times due to asset reuse.
Storing shared game data like item stats or configuration
Unity
public class ItemData {
    public int damage;
    public float weight;
}

// Each instance creates its own copy
var sword = new ItemData { damage = 10, weight = 2.5f };
var axe = new ItemData { damage = 15, weight = 3.0f };
Each instance duplicates data in memory, increasing load time and memory use.
📉 Performance CostIncreases memory usage linearly with number of instances; slows load time.
Performance Comparison
PatternMemory UsageLoad TimeRuntime OverheadVerdict
Duplicated class instancesHigh - each instance duplicates dataSlower - more data to loadHigh - more allocations[X] Bad
ScriptableObject shared assetsLow - data stored onceFaster - asset reusedLow - references only[OK] Good
Rendering Pipeline
ScriptableObjects are loaded as assets before gameplay, so they reduce runtime data duplication and memory pressure.
Asset Loading
Memory Management
⚠️ BottleneckMemory usage during gameplay if data is duplicated instead of shared.
Optimization Tips
1Use ScriptableObjects to store shared game data once and reference it to save memory.
2Avoid duplicating data in multiple class instances to reduce load time and memory overhead.
3Check memory usage in Unity Profiler to ensure data sharing is effective.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using ScriptableObjects for game data?
AThey store data once and share it, reducing memory use.
BThey automatically speed up rendering of game objects.
CThey compress data to reduce file size on disk.
DThey allow data to be edited only at runtime.
DevTools: Unity Profiler
How to check: Open Unity Profiler, run the game, and check Memory and CPU usage during load and gameplay.
What to look for: Look for high memory allocations from duplicated data and long load times; ScriptableObjects reduce these.