Basic Combat: Move Within Range: null reference exception

Line 13 from Fighter.cs

        bool isInRange = Vector3.Distance(transform.position, target.position) < weaponRange;

Causes

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

And locks up game editor from running when you click play. Is this resolved in a later lecture? Not sure what I am missing since target exists, and the object which this script is attached exists…

Found the answer - its in other threads as well.

Replace isInRange with a function…
bool IsInRange()
{
return Vector3.Distance(transform.position, target.position) < weaponRange;
}

and remove line 13.

1 Like

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

Privacy & Terms