Object not set at instance issue

Hey guys,

So I’ve been doing something really basic but I keep getting an error: “Object not set to instance of object”.

It’s a really simple bit of code:

void LadderClimb()
	{
		Player.GetComponent<PlayerController> ()._playerAnimator.SetBool("IsClimbing",true);

		Player.transform.Translate ( new Vector3 (0, _climbSpeed, 0) * Time.deltaTime);
	}

I’ve tried many solutions, but get the same error when trying to set a bool on the PlayerController script I made. These solutions include:

void LadderClimb()
	{
         PlayerController pc = Player.gameObject.GetComponent<PlayerController>();
         pc._playerAnimator.SetBool("IsClimbing",true);
	}

I have also checked and double checked that the Player has “IsClimbing” on it’s animator. I have also checked using the PlayerController Script that setting a basic Input of O key down can it fire the Animation it will… It just wont fire from my Ladder Script.

If anyone can help me diagnose the script, I’d really appreciate it!

This simply means that something you are calling a function on or accessing is null.

is Player null?
Does it have a PlayerController component?
Does that component have a non-null _playerAnimator?

Either use your debugger, or split the calling up to find exactly where the problem is:

if (Player == null)
  Debug.Log("player null");

PlayerController pc = Player.GetComponent<PlayerController>();
if (pc == null)
  Debug.Log("controller null");

Animator anim = pc._playerAnimator;
if (anim == null)
  Debug.Log("anim is null");