Null Reference Exception IsAttackerInLane()

Hello, I some how broke something when I was working on the Lizard doing his eating attack animation.

The first spawn point, my defenders are not doing anything and that’s when i am seeing that null reference. they do attack on the other lines just not the first one.

When I click on the error it takes me back to the shooter script. The defenders are working in the other spawn points just trying to figure out what may I have broken to cause the last line.

private bool IsAttackerInLane()
{
    if (myLaneSpawner.transform.childCount <= 0)
    {
        return false;
    }
    else
    {
        return true;
    }
  
}

I’ve even attempted to make my core game area a little bigger in hopes it will detect.

1 Like

Hi,

There is a variable in your IsAttackerInLane method: myLaneSpawner.

Check where a lane gets assigned to this variable. The y-coordinates of both the defender and the spawner must be equal. Otherwise, the condition gets evaluated to false, and nothing gets assigned to myLaneSpawner. If the variable is empty, it is null, thus the NullReferenceException.

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

Privacy & Terms