Hello to those, who’s reading this thread!
I’ve got such a strange problem and tried to fight with it for two days, but without success.
So:
I’ve got
public class CreateMap : MonoBehaviour
in which i’ve got
public Dictionary<string, CellClass> MapObjectsDictionray;
By the way here is CellClass class that is written below CreateMap (not inside create map) :
public class CellClass
{
private Vector2 Position;
private EnvironmentType type = EnvironmentType.Plain;
public CellClass (Vector2 NewPosition, EnvironmentType NewType)
{
Position = NewPosition;
type = NewType;
}
public Vector2 PositionAcessor ()
{
return Position;
}
public EnvironmentType TypeAcessor ()
{
return type;
}
};
in Awake Function i’ve got
MapObjectsDictionray = new Dictionary<string, CellClass> ();
So we are close to the porblem, i also got function that returns EnvironmentType
public EnvironmentType GetTypeOfCell (string id)
{
if (MapObjectsDictionray.ContainsKey (id)) {
CellClass temp = MapObjectsDictionray[id];
return temp.TypeAcessor();
} else {
return EnvironmentType.Plain;
}
}
When i trying to acess this funtion, from other script and when if (MapObjectsDictionray.ContainsKey (id)) leads us to else - everything is pretty, but if we got key in dictionary i ussualy got NullRefrenceException
in line with CellClass temp = MapObjectsDictionray[id]; and for some reason temp is always null!
Class, that uses EnvironmentType don’t initialize before CreateMap class , and respectively could not meet empty dictionary;
So , bravest coders , please help me to deal with this.
Thank you in advance!