Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Is there a way to stop Dictionaries from resetting, when changes in the code are made?

Discussion in 'Scripting' started by Jazzhorse, Apr 14, 2020.

  1. Jazzhorse

    Jazzhorse

    Joined:
    Aug 11, 2018
    Posts:
    3
    Hey there,

    Everytime I change something in my code, my Dictionaries getting reinitialized and emptied.
    Is there any way to stop the compiler from dooing that?

    Example:
    I have a ScriptableObject like this:
    Code (CSharp):
    1. [CreateAssetMenu(fileName = "SaveGame", menuName = "Assets/SaveGame", order = 1)]
    2. public class SaveGame : ScriptableObject
    3. {
    4.     [SerializeReference]
    5.     public Dictionary<string, bool> playerBools;
    6. }
    When creating an instance in the assets-folder, I can add all the strings an bools I want.
    At the moment all I have saved are some bools for the player-character, but this script needs to be extented in the future. I really dont want to reset all my variables, when adding something to this script.
     
    Last edited: Apr 14, 2020
  2. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    488
    Jazzhorse likes this.
  3. Jazzhorse

    Jazzhorse

    Joined:
    Aug 11, 2018
    Posts:
    3
    I didn't know that Dictionaries arent serialized in Unity.
    Will have a look at that asset, thanks.