NullReferenceException: Object reference not set to an instance of an object (155237)

Help? I’m trying to create basic AI to follow the player around, keep getting this ‘error’ and the Enemy Tank never moves? Here is a link to my code for the EnemyMovement Class

Could you help @Soraphis?

–

1 Answer

1

The console will tell you which line the error is occurring on. Whichever object you’re referencing there hasn’t been set.

Looking at your code (which you should post directly using the “101010” button) my guess is that you should change

player = GameObject.FindGameObjectWithTag ("Player").transform;

to

player = GameObject.FindWithTag("Player").transform;

And in Awake(), change

NavMeshAgent agent = GetComponent<NavMeshAgent> ();

to

agent = GetComponent<NavMeshAgent>();

What do you mean I should post directly using the "101010" button? And let me try that real quick. And it is on line 29 of the file.

–

Still not working. Not sure the problem. Same error. Same Line.

–

After changing the awake function, it fixed the problem! Thank you! :)

–