How to save a scene exactly as it is ?
Hello, I recently started a new game, and I have the following problem: I need to create the possibility to save the scene exactly in the state that it is at a certain point in time. That means the position of objects and values of variables. I have seen several examples on the internet but most them are saving only the position of objects and under certain conditions. The idea is that I already created the game and finished basically almost all of it, but it needs to be able to save the scene with everything exactly as it is, player condition and position, weapons, the number of bullets, all data about monsters position and situation, etc ... so is there any possibility to freeze the scene (on exit) and return to it when you reopen the game ? [sorry for any language mistakes I don't speak English very well]
No answers ... :( ... I guess there is no way to do it ... I read some more materials on the internet on this subject and I found out that in Unity to be able to save the scene with everything exactly as it is, player condition and position, weapons, the number of bullets, and other info from other objects all the data about them must be store manually using a special script for every intractable object that saves all that information from all the variables in a file or something .... this is so bad .... it's lame .... seriously
You'll have to do that manually, serialization is your friend.
Thanks. I read some more materials on the internet on serialization and data saving in Unity. It is going to be a hard work to do this for every intractable object and for every parameter that I want saved .... but since this is the only way .... I don't have any choice.
Answer by toddisarockstar · Mar 14, 2016 at 09:19 PM
this is how you do it. you whould collect all the positions weapons, rotations blah, blah, of all your objects in some sort of format. I would recommend maybe a text file with bunches of numbers seperated by commas in some format you create based on what your game needs and a format to your liking. your game would look for the file when the the game reopens. and obviosle you would then split with separators and manually move the numbers into spawn functions and reasign whatever nessesarry variable in your game. If you are Building for windows or mac its perty simple to access a hard drive to write your custom file. web players are tough. firewalls like to block these sort of things. you might need to read/write to a website or server for a webplayer game. there is no easy or automatic way to do what you are asking.
Thanks. I read some more materials on the internet on serialization and data saving in Unity. It's a lot of work when you have many objects of different types but maybe I can come up with some crazy algorithm to solve it in an clear and nice way .
eh, really you would just write the relevant stuff. for example you pry wouldnt really need to save player rotation, pry just location....maybe even rounded off. if he ad a gun, and there was say 4 different guns all you would need is one number 1 to 4. I can post a simple code example to read/write to a harddrive from my last game if you want. if your game is not multiplayer it might be a bit simpler than it sounds just to snap player to positions with scores and stuff
you wouldnt bother saving anything about the level unless its randomly generated or something like that. you could toss in a couple numbers to represent a tree knocked over or something like that.
Thanks! I found some good examples on serialization and managed to save the player data, now I have to do it for intractable objects and some enemies.