I keep getting the error "NullReferenceException: Object reference not set to an instance of an object PlayerMovement.FixedUpdate () (at Assets/Scripts/PlayerMovement.cs:18)"
I do not know what I'm doing wrong. I've followed the instructions in the 2nd tutorial of unity and i'm trying to learn the basics in using it. If anyone could help me identify the error it will be deeply appreciated. It tells me that line 18 is not working. I know that its not reading the object correctly, but I can't identify the problem or how to solve it. I'm still learning the basics in unity. " using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { private Rigidbody rb; void start () { rb = GetComponent (); } void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement);
}
}"
Answer by Yuzuke · May 19, 2017 at 01:20 AM
rb = GetComponent ();
this line makes no sense. I think you're suppose to finish this line like :
rb = GetComponent<Rigidbody>();
in fact I'm wondering why there's no compilation errors before you run this code. there should be sth. like :
Using the generic method `UnityEngine.Component.GetComponent<T>()' requires `1' type argument(s)
anyway, maybe you wanna get yourself a C# scripting book before digging into those tutorials . @luciob22
Your answer
![](https://koobas.hobune.stream/wayback/20220612122326im_/https://answers.unity.com/themes/thub/images/avi.jpg)