Hi,
I am using multi hirarchy inheritance for my character controller script.
However, I have noticed a weird behavior: The call base.start()
is skipping intermediate class and calling base.base.start instead.
I just confirmed this by debugging.
Any insights?
Thanks
It shouldn’t miss one if you’re calling from the correct subclass.
You’ll have to call a virtual method that will be called from the base Start.
i.e.
public class A : MonoBehaviour
{
void Start()
{
Init()
}
virtual void Init() { }
}
public class B : A
{
override void Init()
{
base.Init();
}
}
public class C : B
{
override void Init()
{
base.Init();
}
}
Or make Start a virtual method that’s overridden and you call base too
public class A : MonoBehaviour
{
protected virtual void Start()
{
}
}
public class B : A
{
protected override void Start()
{
base.Start();
}
}
public class C : B
{
override void Start()
{
base.Start();
}
}