I allow placement of Buildings and other objects in my game. This means I need to save and load the Buildings position and some other dynamic data when I exit/enter the game, I need a List of BuildingData to save all my buildings.
However, I also have plenty of constant data for my buildings, like name, description, etc. A building can also have extensions that is of type GameObject, which cannot be Serialized, so saving/loading the constant data is not an option.
So, with all this, I now have a Building GameObject, with a reference to its dynamic and constant data, as well as Datamanager with a reference to a BuildingList that I can use to save/load.
I hate the fact that I am using 2 classes to store data for the Building (Dynamic/Constant), is there a better way?
Currently I am using a Scriptable Object for the constant data, but I don’t love that either, since that just adds even more overhead to everything, and doesnt really provide any benefit in this scenario (correct me if I’m wrong).
I’m not sure where I see an issue. Your constant data contains information on stuff that either doesn’t change or base stats. Your buildings name, description and such. While your other data contains the world layout. I would say the big thing is, you don’t need to save out constant data, just some way to retrieve it.
So if a player puts a building down, I know that “store1” is at location x. From a save point, I’m only saving out that store1 is there. I don’t need all the other info. Then when I load up, I lookup the information for store1 and setup the scene as I need to.
saving and loading in unity is a mess there is no “clean” build in solution afaik. You can use JsonUtility which saves all data of a Mono which is normally not what you want, because there is data you don’t want to save but still gets saved. So you end up either creating your own serialization method which is a shitload of work or using 2 classes. I’m using a scriptable object as second class, but I don’t like this solution as well.