!Help! NullReferenceException: Object reference not set to an instance of an object Player_Control.FixedUpdate () (at Assets/Scripts/Player_Control.cs:20)

I’m new to unity and decided to start by going through the roll-a-ball video tutorial. I made this script to control the player through keyboard inputs:

using UnityEngine;
using System.Collections;

public class Player_Control : MonoBehaviour
{

private Rigidbody rb;

void start()
{
    rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

    rb.AddForce(movement);
}

}

But when i run the game it stops after the first frame with no player movement, and brings up this error message - NullReferenceException: Object reference not set to an instance of an object
Player_Control.FixedUpdate () (at Assets/Scripts/Player_Control.cs:20)

Any help would be much appreciated

Jelleyzeefirst,

You have written start() starting from small letter. Start() function should be written from upper letter (like all functions in C#) :wink:

I’m not sure what line is the problem in (because this fragment of script doesn’t have 20 lines as the error says ;). But it looks like it’s this line: rb = GetComponent<Rigidbody>();
Probably it’s because the GameObject to which this script is attached doesn’t have RigidBody component and thus the script couldn’t find it.
Just add in Unity RigidBody Component to this object (Player) and it should work fine.

The game object does have a rigid body component attached and deleting and re adding it didn’t work?