0

I am trying to use a boollean from another script. But I get the error message "Object reference not set to an instance of an object CameraController.Update()". Any ideas?

public Controller mPlayer;

  void start()
        {mPlayer = GameObject.Find("Player").GetComponent<Controller>();}

  void Update()
    if (mPlayer.testScript)
       {Do Stuff}

2 Answers 2

1

You need to be careful of case sensitivity. It's (capital S) Start()

It's:

void Start()
{
mPlayer = GameObject.Find("Player").GetComponent<Controller>();
}
Sign up to request clarification or add additional context in comments.

1 Comment

I spent 2 hours trying to solve this last night! I thought I was going insane! Thank you!
1

The error is clear

"Object reference not set to an instance of an object CameraController.Update()".

you are trying to use a null object as if it was a properly referenced object. Most of the time, when you try to assign value into object, and if the value is null, then this kind of exception occur.

try debug the code line by line and find the null value occur.

2 Comments

Might be clear to you, but I am unclear what that error message is saying
For future reference, this error is saying that in the function CameraController.Update() there is some code trying to access an object that is currently set to null. In this case, the only thing it can be is mPlayer. Following that discovery you should now know that mPlayer hasn't been set and therefore something went wrong with Start().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.