Hi, can somebody tell me why the following happens: I have a class A Code (csharp): public class ClassA : MonoBehaviour { protected int i = 1; } and three classes B, C and D which derives from A. Code (csharp): public class ClassB : ClassA { public void Print(){ Debug.Log("B: " + i); } public void Start(){ Print(); } } Code (csharp): public class ClassC : ClassA { public ClassC(int j){ } public void Print(){ Debug.Log("C: " + i); } public void Start(){ Print(); } } Code (csharp): public class ClassD : ClassA { public ClassD(){} public ClassD(int j){ } public void Print(){ Debug.Log("D: " + i); } public void Start(){ Print(); } } The output for running this (one game object with B and one with C) is: C: 0 D: 1 B: 1 Why hasn't i been initialised in C?
Ahh, I think I understand now. The unity "side" of the object exists, and it can call Print(), but since I have declared a constructor I no longer get the default one and mono can't figure out how to create the object as there are no zero argument constructor, and hence the null value of i.