GetComponent() not required

Morning Jonathan,

Sorry its taken me so long to start working through the Unity content.

Just working through this lecture, just an observation.

when we publicly expose say the redSphere with type Rigidbody

public Rigidbody redSphere;


the GetComponent<>() isn't needed to get the Rigidbody component since the public slot will already take care of that i think.

redSphere = redSphere.GetComponent<Rigidbody>();


  • Jonathan Gonzalez(jgonzalez) replied

    Yes that's correct. Unity has gone back and forth on what components require using "GetComponent" so it's just something I'm used to do doing. Previously it would be required regardless with certain components. Hopefully it stays that way this time as it is easier to work with in this way.