Quick Question with my code (null reference exception)

So I’m getting this run time error and I’m completely stumped. Even after I searched it up I still don’t know what I am doing wrong.
I highlighted the problem any help would be greatly appreciated.
ps sorry for posting so much but I am trying to get better.

using UnityEngine;
using System.Collections;
using Assets.Code.Interfaces;
namespace Assets.Code.States.PlayerStates
{
public class MoveRightPlayerState : PlayerMoveInterface
{
public static CharacterController controller;
public float speed = 100.0F;
private Vector3 moveDirection = Vector3.zero;
public void StateUpdate()
{
}

public MoveRightPlayerState (PlayerMoveStateManager managerRef)
{
Debug.Log (“Move Right State”);
controller = PlayerMoveStateManager.controller;
if (controller.isGrounded)
{
Debug.Log (“Character Controller”);
moveDirection = Vector3.right;
controller.Move(moveDirection * Time.deltaTime*speed);
}
}

}

}

Like it says, PlayerMoveStateManager.controller is null. You haven’t assigned controller a value anywhere in that code, so unless you’re doing it somewhere else, it’s going to be null.

ok but how would I do that for a controller?
I forgot to mention that the error says “object reference not set to an instance of an object”
Thank you for replying

Well, normally you would implement MonoBehaviour, make a public CharacterController variable, and drag and drop the controller you want onto it. I’m not sure why you have a separate class or why you are making the variable static, but assuming that is what you want, you can do something like this:

controller = GameObject.Find("Player").GetComponent<CharacterController>();

That’s assuming your player is named “Player”.

thank you and I am making a movement state machine for the player. I’m a C#/unity novice and I’m just trying to make things work.
so all I needed to do was add find player well learning something new everyday

it didn’t work
do you know what an instance of an object is? If I know that I can figure it out. thanks for your previous help anyways.

The upshot of it is - PlayerMoveStateManager.controller is null. However you make it not null is up to you.

ok here is the updated state. I just realized that there is no point in checking if it’s grounded since I’m doing that earlier

Same problem as before however.

using UnityEngine;
using System.Collections;
using Assets.Code.Interfaces;
namespace Assets.Code.States.PlayerStates
{
public class MoveRightPlayerState : PlayerMoveInterface
{
public CharacterController controller=PlayerMoveStateManager.controller;
public float speed = 100.0F;
private Vector3 moveDirection = Vector3.zero;
public void StateUpdate()
{
}

public MoveRightPlayerState (PlayerMoveStateManager managerRef)
{

Debug.Log (“Move Right State”);
controller=PlayerMoveStateManager.controller;
Debug.Log (“Character Controller”);
moveDirection = Vector3.right;
controller.Move(moveDirection * Time.deltaTime*speed);

}

}
}