NullReferenceException: Object reference not set to an instance of an object problem

Hi guys i am really new to programming and unity and I keep getting this error, I was just trying to learn how to make my character load and this error comes up:

NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.FixedUpdate () (at Assets/PlayerMovement.cs:26)

And this is my code:

public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;

public float runSpeed = 40f;

float horizontalMove = 0f;

// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw(“Horizontal”) * runSpeed;

}

void FixedUpdate()
{

// Move Character

controller.Move(horizontalMove * Time.fixedDeltaTime, false, false);

}
}

Can you please help me please.

NullReferenceException tells you that some reference does not exist. That happens at line 26, which i guess is controller.Move. To make people guess less, it’s advisable to use code tags for code examples :wink:

Anyways, you probably did not assign ‘controller’ through the inspector, thus it’s an empty reference, or ‘null’.