- Home /
Saving class data without having lots of references?
[System.Serializable]
public class Level_Data
{
public string LVLID;
public bool LevelComplete;[Space(20)]
public string AnimationState;
public Wire_Dictionary Wires;
public Switch_Dictionary Switches;
public Slider_Dictionary Sliders;
public Moving_Part_Dictionary Moving_Parts;
// switch dictionary
// transmitter dictionary
//cartirge dictionary
}
I'm wanting to save level data for each level which includes the data for all the levelobjects in the level. The thing is each level is different, most levels will only include a few different levelobjects. So when I go to save a level I have an empty dictionary of every different levelobject that could be in a level and maybe only one or two actual populated dictionaries.
Is this fine to have it like this? it seems like a bit of a waste also it's a bit ugly in the inspector. Or is there a way to save just the levelobjects in that level and not have a refence to every possible levelobject that could be in the leveldata class.
For how the game works I would much prefer to save the leveldata all together and not have a file for each levelobject data.
I'm using a serialized dictionary as well which lets me serialize dictionaries. For example I have WireDictionary (WireData is variables I want to save for the wire) then on the wire object I just pass that onto it.
I've had a look at interfaces, and sub classes and I just can't get my head around it.
not sure what to do, having possible lots and lots of references that aren't gonna be used is a bit of waste of space.
Answer by rh_galaxy · Jun 03 at 03:05 AM
Just my thoughts here. You don't need a file for each levelobject data. You need to make an external editor that saves the relevant objects/data and then a loader that populate your data structures in your game.
I have my levels in text format, for clarity and easy parsing. Example:
*MAPTYPE MISSION
*MAPSIZE 50 60
*MAPFILE mission14.txt
*TILESIZE 32
*TILESET ts_evil.png
*MAXPLAYERS 2
*PLAYERSTARTPOS 946 381
*PLAYERSTARTPOS 864 163
*LANDINGZONE 224 1884 3 CARGOBASE NOANTENNA 2 10 10
*LANDINGZONE 96 1468 3 CARGOBASE NOANTENNA 1 20
*LANDINGZONE 863 220 3 HOMEBASE ANTENNA
*ENEMY 0
*ANGLE 0
*FIREINTERVAL 1800
*SPEED 80
*NUMWAYPOINTS 2
*WAYPOINTSX 47 47
*WAYPOINTSY 1721 1600
...
Sorry if I miss the point of your dictionaries, but you should focus on what your level consist of and save/load these things in your own code. Serialization can't beat that.
I'm not entirely sure what you want to do, but this is how I have done it and it may give you some new ideas. I don't use the Inspector for level editing.
Your answer
Follow this Question
Related Questions
Derived Class Serialization 3 Answers
How to choose base class to make Inherit C# 2 Answers
Saving/Loading a GameObject with Texture on Unity3D with Unity Serializer 0 Answers
I am getting a serialization exception error when trying to save and load in Unity? 2 Answers
How to structure my project so that I can save/load information? 0 Answers