Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Looking for an way to save the game

Discussion in 'World Building' started by RubenVanOostveen, Sep 9, 2021.

  1. RubenVanOostveen


    Jul 31, 2020
    Alot of youtube tutorials i follow work no more or doesn't apply to my game. All of my videogame is working with turning off and on game objects / modeuals. Im looking basically for an save method to save the unity scene as is. for example:
    object.001 = true
    Car.012 = false
    when it loads back up the game it puts the correct things on and off like it was when the game ended.
    I've tried to look in which / what forum post it needs to be at but I think this is the best forum threat.
  2. JoeStrout


    Jan 14, 2011
    Actually, the Scripting forum would be the correct one.

    There is no shortcut for this that I'm aware of. You will need to iterate over your objects, and build a string representing all the state you need to save. You can store this string in PlayerPrefs. Then when you load, you'll check PlayerPrefs for that data, parse it out, and update the state of your objects.
    Kurt-Dekker likes this.
  3. Kurt-Dekker


    Mar 16, 2013
    Here are some load/save notes:

    Don't use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

    When loading, you can never re-create a MonoBehaviour or ScriptableObject instance directly from JSON. The reason is they are hybrid C# and native engine objects, and when the JSON package calls
    to make one, it cannot make the native engine portion of the object.

    Instead you must first create the MonoBehaviour using AddComponent<T>() on a GameObject instance, or use ScriptableObject.CreateInstance<T>() to make your SO, then use the appropriate JSON "populate object" call to fill in its public fields.