Object reference not set to an instance at Compilation step ?
Hi all
I have a compilation error with the (simplified) following code, and I have no idea how to remove it. First, the error :
NullReferenceException: Object reference not set to an instance of an object
ManagementData+Data.GetMaxAmo () (at Assets/Player/Script.cs:xx)
ManagementData+Data..ctor () (at Assets/Scripts/Script.cs:yy)
ManagementData..ctor () (at Assets/Scripts/Script.cs:zz)
NullReferenceException: Object reference not set to an instance of an object
ManagementData+Data.GetMaxAmo () (at Assets/Player/Script.cs:xx)
ManagementData+Data..ctor () (at Assets/Scripts/Script.cs:yy)
I precise that the project runs without error.
Here is the code
public class Management : MonoBehaviour
{
public static Management Instance;
public ManagementData md;
void Awake()
{
if (Instance == null) {
Instance = this;
md = new ManagementData ();
}
}
}
[Serializable]
public class ManagementData
{
public Data data;
public ManagementData()
{
data = new Data ();
}
public int Method1()
{
return 0;
}
}
[Serializable]
public class Data
{
protected int value;
public Data()
{
value = Method2 ();
}
public int Method2()
{
return Management.Instance.md.Method1();
}
}
The line Assets/Scripts/Script.cs:xx refers to the following
return Management.Instance.md.Method1();
The line Assets/Scripts/Script.cs:yy refers to the following
value = Method2 ();
The line Assets/Scripts/Script.cs:zz refers to the following
data = new Data ();
Of course, all the attributes are well instantiated, and I repeat that there is no problem with the execution, just with the compilation step.
I noticed that if I remove the [Serializable] of the class Data, the second error disappears. If I remove also the [Serializable] of the class ManagementData, all the errors disappear.
I hope I've exposed well the situation.
Brett