Object reference not set to an instance of an object

Getting this error:
NullReferenceException: Object reference not set to an instance of an object
RPG.Combat.Fighter.Update() (at Assets/Scripts/Combat/Fighter.cs:23)

I saw a couple of people mention this error and the solution was to add the Action Scheduler script to the Enemy, which I have done, and this error still presents itself. My code for my line 23 is below.

            if (!GetIsInRange())
            {
                GetComponent<Mover>().MoveTo(target.transform.position);
            }

And just for good measure, here is the MoveTo() function from the Mover.cs

public void MoveTo(Vector3 destination)
        {
            navMeshAgent.destination = destination;
            navMeshAgent.isStopped = false;
        }

Edited post because I pasted too much and realized it wasn’t clear where my line 23 was. Line 23 is the GetComponent<> part.

Oh, somewhere along the lines I must have missed adding the Mover script to the enemy prefab. Got it.

That was about to be my first question till I scrolled down. Good job working this out.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms