I'm curious now: Is there a certain way that I need to code, to bring in the Rigidbody component? I was looking at the que...

I'm curious now: Is there a certain way that I need to code, to bring in the Rigidbody component? I was looking at the question from five months ago, and peered at the blog regarding it.
  • Jonathan Gonzalez(jgonzalez) replied

    If you’re going to use something within the Rigidbody component you’ll need to use GetComponent, preferably in the Start function. So if you’re adjusting the speed/gravity of that rigidbody via code then you’ll use GetComponent first to cache that object. If you’re not doing any of that it’s not necessary. So in the script shown in the video it’s not necessary since we’re not using anything specific to rigidbodies, but just using it as a projectile. 

  • jazze replied
    Ahhh, okay. Thanks for clarifying, Jonathan!
  • Jonathan Gonzalez(jgonzalez) replied

    Just to clarify a bit as it can be confusing. Unity will automatically cache these commonly used components for you. In general if you want to access something within a script, you need to tell Unity to Get that component, or “Get that script” so you can access it. That’s all you’re doing with GetComponent. With a Rigidbody it’s not really necessary at the moment to do that since Unity does that in the background, although they have required it in the past (like in Unity 5.0), but not at the moment. 

  • jazze replied
    Oh, that makes even more sense! Thanks! :D