There is a life cycle of class in Unity like a below figure. This cycle had cause the problem on the team project. Today, I studied the feature of class in the Unity.
There are two classes shown in code blocks.
public class A : MonoBehaviour
{
...
private void Awake()
{
...
}
}
public class B : A
{
...
// there is no `Awake` method in B
}
In these case, the B
class in Unity will invoke the Awake method on parent;A
. To prevent the issue, we have to insert the Awake
on B or make the Awake as virtual.
case 1:
public class B : A
{
...
private void Awake()
{
// blank method
}
}
case 2:
public class B : A
{
...
// the A will be modified to `protected virtual void Awake()`
private override void Awake()
{
}
}