- Home /
NullReferenceException: Object reference not set to an instance of an object
So frustrated with making my own charactercontrollers, I have decided to use the default 3rd person. I still have the construction worker attached since I started back from scratch and have yet to attach my model. I am getting this error:
NullReferenceException: Object reference not set to an instance of an object ThirdPersonController.UpdateSmoothedMovementDirection () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js:129) ThirdPersonController.Update () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js:302)
I need to fix this...
You should add the code so someone can tell you what is missing. The first line (NullReferenceException) tells you that you've created a box for something, and are attempting to use what's in the box, without putting anything in the box first. The next 3 lines are telling you where the information, that isn't there, is being used.
What do you mean by you have yet to attach your model? If you haven't assigned a model to a variable that requires a model and your code calls for that variable then this is the empty box I was talking about.
Answer by robertbu · Jul 20, 2014 at 05:00 AM
I have this line as line 129 in the ThirdPersonController script:
var cameraTransform = Camera.main.transform;
My educated guess is that you replaced the tag on the main camera, or you deleted the main camera. The use of 'Camera.main' to access the camera only works if the camera is tagged as 'MainCamera'.
Your answer
Follow this Question
Related Questions
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Pause Script Suddenly Stops Working 0 Answers
NullReferenceException 1 Answer
Object reference exists but also doesn't? 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer