Search Unity

About saving the game

Discussion in 'Scripting' started by skekici, Jun 30, 2021.

  1. skekici

    skekici

    Joined:
    Jan 24, 2021
    Posts:
    30
    Hello, I know how to save and load my game, but I want to add a new game as an extra option, but the user has to delete and reload the game to start over after saving it once, how can I do it?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    Here's all I know about Load/Save:

    https://forum.unity.com/threads/save-system-questions.930366/#post-6087384

    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.

    https://docs.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide

    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
    new
    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.
     
  3. skekici

    skekici

    Joined:
    Jan 24, 2021
    Posts:
    30
    Thank you!
     
    Kurt-Dekker likes this.