Reason for the exposed field rather than a GetComponent?

As in the title, just wondering why we are exposing a lot of the components and then linking them in the editor (with potential to forget links, components etc.) rather than doing a GetComponent in awake like was done most of the time in the RPG course, with potentially a RequireComponenet to safeguard against its deletion?

It’s just the style that Nathan has chosen to work with for this course, largely to show off the new functionality with [field: SerializeField].

Here’s what I did to make things a bit automagic…

void OnValidate()
{
    if(Health==null) Health = GetComponent<Health>();
    if(CharacterController == null) CharacterController = GetComponent<CharacterController>();
    //etc
}
1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms