Performance: ScriptableObjects for game data
MEDIUM IMPACT
This concept affects runtime memory usage and load times by how game data is stored and accessed.
[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;
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 };
| Pattern | Memory Usage | Load Time | Runtime Overhead | Verdict |
|---|---|---|---|---|
| Duplicated class instances | High - each instance duplicates data | Slower - more data to load | High - more allocations | [X] Bad |
| ScriptableObject shared assets | Low - data stored once | Faster - asset reused | Low - references only | [OK] Good |