- Home /
How to save a Gameobject?
There are 4 sets of gameObject A,B,C,D and there are 4 sets of color red, black, white, brown and there is one trigger to check which gameobject has entered. Now suppose A has entered the trigger and now i click on red, now the A gameobjects material is red. Now when i click on save button this A gameobject with new rendermaterial should be saved. So next time when i play the game i should be able to see the saved gameobject. How to achieve this? I feel PlayersPrefs will be involved.
As far as I know, there is no direct way to save the state of a game object while the game is running. Doing so would require you to overwrite the scene or the prefab file, whichever was used by the player to deserialize the game object.
What you want is essentially saving and loading a game state. There are plenty of answered questions on how to that, like this one:
http://answers.unity3d.com/questions/8480/how-to-scrip-a-saveload-game-option.html
Look around the site, you might get a better idea of what you have to do to get your desired effect.
Answer by DaveA · Apr 18, 2013 at 06:44 PM
Yes you could use PlayerPrefs. I would make each object have a unique name, and use that as the key. And each material should have a unique name, and use that name as the value, save the pref as a string. When you restart the game, read out each object name as the key and the value is the name of the material, then set the material from that.
I dont know how to use $$anonymous$$ey. So you are telling me for the colors give playerprefs.setint and for each object playerprefs.string ?
Answer by kilian277 · Apr 18, 2013 at 08:57 PM
You can use the PlayerPrefs class for that. For each color of the gameobject set an int or string based on how yoy want to store it and give it an unique id or key like object1Color. To this for everything you want to store from the gameobject for future use ingame.
Your answer

Follow this Question
Related Questions
Don't Load Collected items 1 Answer
save/load cloned game object 1 Answer
Save gameobject active 1 Answer
Storing GameObject(s) Playerprefs? 1 Answer
How to save a gameObjects on a prefab and variables with a script? 1 Answer