- Home /
Saving Scenes and loading GameObjects?
I have a scene where the player is able to slowly generate more content (like a sim builder), and I need this scene to save the instantiated prefabs for when he/she logs in or out.
The problem I am experience goes two ways, when I use the "don't destroy on load" method the prefabs inter fear with my other scenes (obviously because they are not being destroyed).
So what I'm asking, am I supposed to save each objects position, and how many of that object here are, and re-instantiate each object every time the player reloads the scene? are there easier ways to do this? think about how mine craft keeps the position of all its blocks when the player logs out and back in? is there a way to save a whole scene and reload the whole scene as is or is it more complex?
I've never heard of saving the entire scene but I recommend if it isn't too much, you can try creating PlayerPrefs and just reloading them whenever the player gets back on. Or just set the scripts to not interfere with other scenes.
It's turning out to be like 100 objects , I may make a player pref array, or I might just save all the info into a database and withdraw it with SQL and what not
Troubled question. Are you having problem with DontDestroyOnLoad
or with saving your game state when closing and reopening the application?
Answer by cregox · Apr 20, 2012 at 06:32 PM
If you want to save state between closing and reopening the application, `PlayerPrefs` is the way to go (or maybe PlayerSave, or even XML's or databases). And yes, you'd have to save each thing you want, one by one (make it in the suggested array) and there's no current easier way of doing it.
If, however, you're having issues with DontDestroyOnLoad
, conflicting objects, you have to review your scene & code and remove the conflicts one by one.
PlayerPrefs would require me to use hundreds of variables if I was saving and loading them out individualy, $$anonymous$$y best solution to this was to use player prefs however Ins$$anonymous$$d of saving 1 number each to a different player pref I saved a string of letters and numbers usually 40 characters long, to one player pref, then I used an array which would get each different value out of the pref and resort them into their correct places, so yes Player Prefs is the easier solution to this but it is by no means easy.
Answer by Steven-Walker · Apr 20, 2012 at 03:41 PM
Saving a scene is an editor function that will only work while running Unity. So you will need a different solution when it comes to deploying an app to any platform. I'd suggest writing data to either JSON or XML using the shortest fastest form possible. A database would work well too. Your scene then in Unity will just be the core elements and source prefabs. When your scene loads, the script will have to take care of instantiating all of the prefabs with the data saved previously. I also suggest starting with something really simple and test it on your target platform before getting too far building stuff in the editor.
No, what I am talking about is a Player saving a game as an in game function, for example like saving the game while playing diablo 1 then being able to load everything as it was the next time the player loads into the game.
I considered databasing it, but see my comment on Caue Rego's answer, as that was the easiest solution as databasing is a difficult thing to achieve when using IOS Xcode functionality
Answer by Propagant · Jan 09, 2016 at 05:07 PM
Hi. I made a long script with advanced load and save system. Everything is about File stream. Every position, rotation and scale (basic datas of every object) are saved to txt file as a new Line.
You can save and load your instantiated objects. But first, if you want to load different meshes except Cube, you must create Resources folder in your assets project and duplicate meshes which will be loaded in a future.
Also you can set which objects will not be saved or loaded. You can edit script also, it is free and my without copy... Download here: Save_Load Advanced System by Matt DOWNLOAD
Answer by TheDarkVoid · Apr 20, 2012 at 08:13 PM
add and if block around your don't destroy on load function to control when it is applied.
This doesn't work as when the player quits the game, and reopens, all the objects die anyways, also the objects then stay present in the other scenes which have nothing to do with that game mode.
Your answer
Follow this Question
Related Questions
Saving with PlayerPrefs? How it works? 1 Answer
PlayerPrefs not saving mission info at all. 0 Answers
PlayerPrefs logic and bool? 1 Answer
Save/Load Animation State of Instantiated Prefabs 0 Answers
playerprefs multiple save slots 2 Answers