Hi,
I have a simple setup of scriptable object that stores Building stats (different kinds of buildings which all share some basic stats) : name, cost, income, upkeep, connected to a road etc.
I will create multiple buildings and for each I want to store unique data for some parameters like income, upkeep and connected to road.
Is cloning my SO and saving it into a dictionary with position as key a good way to use Scriptable objects?
Or should I have a new c# class for storing desired stats to which I copy the data - which seems like duplicating the code that is already in scriptable objects.
Thanks!
1 Like
This is a perfectly valid approach, and the coolest thing it gets you is that you may be able to edit those now-unique values at runtime, such as for debugging or testing in the editor.
What you are creating is a SO that is obviously NOT connected to an on-disk asset. This means that the default Unity editor doesn’t give you an easy way to view and modify its contents.
EDIT: actually the default Unity editor DOES allow you to modify these transient SO instances; you need to first show them by putting the reference into a MonoBehaviour field (public or SerializeField) and then doubleclicking on the filled field, which will “dig in” and show you the transient SO, which you can edit live as your game plays.
However, there are at least two inspectors that can, and possibly others, such as AdvancedInspector and/or OdinInspector, both available on the asset store, at least as long as you provide a Monobehavior that has a public reference to those now-cloned ScriptableObjects.
2 Likes