Search Unity

Scriptable object's variable serialization issue

Discussion in 'Editor & General Support' started by IgorAherne, Oct 30, 2014.

  1. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    I have a dictionary stored in a ScriptableObject, which then is saved as an asset.

    Dictionary<Transform,Nodescript> scriptViaTransform= new Dictionary<Transform,Nodescript>();

    Once I load the asset, my editor classes can pass values for storage, but if I Enter/Exit playmode, it looks like the dictionary re-initializes itself. This wipes all the keys/values :<

    Question, how to store the dictionary data in a Scriptable object so that its dictionary doesn't re-initialize itself upon the initialization? And how do I initialize dictionary only once?

    Thank you
     
  2. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
  3. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Thank you, it's exactly what I was looking for.

    I have a very strange question in addition, but if I would be referencing an object with a "new" keyword in the scriptable object, granted that it's not a dictionary, does it mean the variable gets initialized with a new object every time this Scriptable object asset is loaded into other classes?