Unity 5.3.5 'Component.rigidbody' is obsolete:(UnityUpgradable)

I get this error in unity 5.3.5

Error CS0619 ‘Component.rigidbody’ is obsolete: ‘Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)’

I had to preface rigidBody and the GetComponent call with “this.”

 private Rigidbody   rigidBody;
 this.rigidBody = this.GetComponent<Rigidbody>();
1 Like

I suppose you used the generic type GetComponent<RigidBody>(); If not that’s the safest way. Also, if you don’t use the variable name “rigidbody” but any other name (such as rb, rigidBody, etc…) MonoDev won’t complain. The similarity to the deprecated gameobject.rigidbody makes it warn even when you use GetComponent() correctly.

could you not just go

rigidBody = GetComponent<Rigidbody>(); 

that’s what is normally done.

You could also try

rigidBody = GetComponentOfType<Rigidbody>();

Privacy & Terms