I'm setting up an inheritance system for my project in Unity using C#.
Entity : MonoBehaviour // Humanoid : Entity
I'm doing this so I can setup properties within each class type, specific to the type of mob it is within the game.
public class Entity : MonoBehaviour
{
public Animator anim;
public CapsuleCollider capsuleCollider;
void Start()
{
anim = GetComponent<Animator>();
capsuleCollider = GetComponent<CapsuleCollider>();
}
}
public class Humanoid : Entity
{
void Start()
{
capsuleCollider.radius = 0.3f;
}
}
My issue is that the GameObject Humanoid is attached to won't run their Start() method after Entity's start method has run. It throws this error since they're trying to run at the same time:
UnassignedReferenceException: The variable capsuleCollider of NPC has not been assigned.
So I'm unsure how to hook into (I believe that's the correct terminology) the end of my Entity's Start() method with my Humanoid's Start() method.
I could change Entity's start to Awake() and that might fix my problem, but I want to setup multiple levels of inheritance so that wouldn't work between all of them.