how do you fix a NullReferenceException: Object reference not set to an instance of an object PlayerControls.FixedUpdate () (at Assets/Script/PlayerControls.cs:20) error in MonoDevelop-Unity
I was watching the Roll-A-Ball tutorial for my Unity 5.6.of3 Personal and I followed every thing perfectly, but i still came up with this: NullReferenceException: Object reference not set to an instance of an object PlayerControls.FixedUpdate () (at Assets/Script/PlayerControls.cs:20). My c sharp script was :
Answer by SpaceManDan · May 25, 2017 at 11:10 AM
Double click on the error and it will open to the line where the error was thrown.
Also, if I'm not mistaken, the 20 at the end of that error is the line number the error occurred, so in your case it's:
rb.addForce(movement)
My guess is that you forgot add a rigidBody component to the gameobject the script is on. The script looks ok.
A NullReferenceException means that the variable "rb" is null. So that tells you right there it didn't find a rigidBody.
Here is how to add a rigidBody: Select your object in your Hierarchy view and look at it in the Inspector. Find the Add Component button and press it. Select Physics -> Rigidbody. TADA!
Your answer
