In my game i cant just save some table, because it ruins all the code. I need the way to save the whole scene and to load it again at the start of the game. It doesn’t has to be a json solution, I need anything that can work. Thank you in advance!
I think this has been asked before (please search). I think the answer is no. You can save the model of the view (as string or JSON or whatever) and then reload the model to the same view.
As agramonte says, you’ll need to save the state of each object (type, position, rotation, image filename etc.) and then re-create them all when loading the game.
I am making a real-time strategy game in Unity, and ended up making the ‘new game’ state just a specific hard-coded saved game. So all my code to create objects requires a saved-game format input rather than making objects and then working out how to save/load them.
How can i do it?
I think you’re right and if I won’t find any other solution, I’ll use yours one.
It’d always help out a lot to know exactly what kind of data you’d need to save, but @agramonte and @nick_sherman have already pointed out the obvious. Part of that obviousness is that your data can most likely be saved in a table, but maybe you just haven’t figured out how yet.
The simplest approach to issues like this is to always plan ahead. Think of all of the values/data that you need to store and then just create your game around this idea.
For instance, I worked on a cartoon-ish top-down shooter some time ago where levels consisted of pseudo-randomly generated terrain features as well as units for the player and the AI to control. At the start of development, I thought about all of the information I’d need to store for each terrain feature and for each unit. These were simply x and y coordinates, rotation, scale, terrain/unit type, HP, etc.
So, basically I was dealing with “a large” numbers of tables. My approach was simple: determine if the game is being loaded or if it is a new game, i.e. whether the map should be loaded or generated, etc. In either case, I had a function that looped through every terrain feature and unit. As the function went through the tables (i.e. terrain features or units) one by one, it looked at what the terrain’s/unit’s type was. This type determined what graphic was used, then HP value was used to create the HP bar (well, duh? :P), rotation, x and y to position each object, etc. etc.
The only difference between starting a new game and loading an existing one was whether the HP, rotation, x, y, etc. entries were filled with default values or stored values. So, whenever I needed to save the game, I simply looped through all existing terrain features and units and created a table with them in it.
I am creating a kind of a rpg game, and all troubles are starting when I’m trying to load my inventory. Load function can’t load images.
Maybe your post has just given me an excellent idea. I’m gonna try it right now.
I think this has been asked before (please search). I think the answer is no. You can save the model of the view (as string or JSON or whatever) and then reload the model to the same view.
As agramonte says, you’ll need to save the state of each object (type, position, rotation, image filename etc.) and then re-create them all when loading the game.
I am making a real-time strategy game in Unity, and ended up making the ‘new game’ state just a specific hard-coded saved game. So all my code to create objects requires a saved-game format input rather than making objects and then working out how to save/load them.
How can i do it?
I think you’re right and if I won’t find any other solution, I’ll use yours one.
It’d always help out a lot to know exactly what kind of data you’d need to save, but @agramonte and @nick_sherman have already pointed out the obvious. Part of that obviousness is that your data can most likely be saved in a table, but maybe you just haven’t figured out how yet.
The simplest approach to issues like this is to always plan ahead. Think of all of the values/data that you need to store and then just create your game around this idea.
For instance, I worked on a cartoon-ish top-down shooter some time ago where levels consisted of pseudo-randomly generated terrain features as well as units for the player and the AI to control. At the start of development, I thought about all of the information I’d need to store for each terrain feature and for each unit. These were simply x and y coordinates, rotation, scale, terrain/unit type, HP, etc.
So, basically I was dealing with “a large” numbers of tables. My approach was simple: determine if the game is being loaded or if it is a new game, i.e. whether the map should be loaded or generated, etc. In either case, I had a function that looped through every terrain feature and unit. As the function went through the tables (i.e. terrain features or units) one by one, it looked at what the terrain’s/unit’s type was. This type determined what graphic was used, then HP value was used to create the HP bar (well, duh? :P), rotation, x and y to position each object, etc. etc.
The only difference between starting a new game and loading an existing one was whether the HP, rotation, x, y, etc. entries were filled with default values or stored values. So, whenever I needed to save the game, I simply looped through all existing terrain features and units and created a table with them in it.
I am creating a kind of a rpg game, and all troubles are starting when I’m trying to load my inventory. Load function can’t load images.
Maybe your post has just given me an excellent idea. I’m gonna try it right now.