0

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

StarterAssets.ThirdPersonController.Move () (at Assets/Scripts/ThirdPersonController.cs:258)

StarterAssets.ThirdPersonController.Update () (at Assets/Scripts/ThirdPersonController.cs:161)

from 155 to 161 line:

private void Update()
        {
            _hasAnimator = TryGetComponent(out _animator);

            JumpAndGravity();
            GroundedCheck();
            Move();

from 257 to 265

{
                _targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg +
                                  _mainCamera.transform.eulerAngles.y;
                float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, _targetRotation, ref _rotationVelocity,
                    RotationSmoothTime);

                // rotate to face input direction relative to camera position
                transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
            }

What causes the error?

Ryan
  • 13
  • 4
  • 1
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – BugFinder Dec 03 '22 at 11:06

2 Answers2

0

In Unity, the most times i see this Exception, it is because I did not set a public variable or a [SerializeField] in the Inspector. If you then try to use it in your script, this Error occures.

Kaa
  • 11
  • 2
0

Errors like these just points that you are either accessing a private/non-existent variable/method. Check whether if you declare public on your variables.

VgReborn
  • 16
  • 2