Question by 
               newGuyInThat · Jul 26, 2017 at 11:58 PM · 
                c#serializationdictionary  
              
 
              Unity is reseting Dictionary when game is playing
I have a class named Item, I am storing instances of this class in list. List is created before game starts, everything works fine in that moment but when I am playing, items still are in list but components Dictionary in each seems to be reset because it haven't got any elements, before game it has.
This is my Item class:
 [Serializable]
 public class Item
 {
     public string Name { get; }
 
     private Dictionary<Type, ItemComponent> components = new Dictionary<Type, ItemComponent>(); 
 
     public comp GetItemComponent<comp>() where comp : ItemComponent
     {
         Debug.Log(components == null); //in game shows true
 
         return
              components.Values.OfType<comp>().FirstOrDefault();
     }
 
     public Item AddItemComponent(ItemComponent component)
     {
         components.Add(component.GetType(), component);
         return this;
     }
 
     public Item(string name, string imagePath)
     {
         //components = new Dictionary<Type, ItemComponent>();
 
         Name = name;
         ImagePath = imagePath;
     }
 }
 
 
               I am not reset or changing items during game.
What could be the problem? Is it connected with Unity serialization limitations?
               Comment
              
 
               
              Your answer