Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Score, Enemies, and Game State Create Enemy Navigation and AI

Bird is not moving? (NullReferenceException)

The bird isn't moving - I've run through the video 4 times now.

  • My script code (BirdMovement) looks exactly as Nicks
  • Navigation Bake settings is also equal, and the Enviroment is baked.
  • Birds Nav Mesh Agent settings is equal to Nicks
  • And weirdest of all: The Bird Movement script has the reference to the Player game objects Transform (from the hierachy), although the NullReferenceException says "Object reference not set to an instance of an object" The exception happens at the line: birdAgent.SetDestination(target.position);

I don't get, why this error happens...

Edit: Also I have reviewed the project and the code, both on mac and windows. And both in MonoDevelop and Visual Studio. - - > Same exception and behavior.

It's been a while since I've completed that course, but usually with Unity it's a simple manner of forgetting to assign the right object in the inspector. Check the inspector for the object that holds the script in question and make sure your transform has a reference to the needed gameObject. If it does, perhaps sharing the relevant code, a screenshot of the inspectors for the objects in question, and the entirety of the error message would help to better unravel your problem.

1 Answer

Alan Mattanó
PLUS
Alan Mattanó
Courses Plus Student 12,188 Points

Try to close Visual studio and Unity. open unity and look if the Game Object is drag and drop into the inspector field. then run and look if is triggering the error.