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 Cameras in Unity Camera Movement Scripting a Tracking Camera

The code works but an error keeps populating in the console

So the code works and my cameras switch and fade in and out but I keep getting one of these errors thrown per second in the console:

NullReferenceException: Object reference not set to an instance of an object CameraManager.SwitchCamera (Int32 cameraIndex) (at Assets/Scripts/CameraManager.cs:54) CameraManager.Update () (at Assets/Scripts/CameraManager.cs:37)

I can't seem to suss out what it is since as far as I can tell I have the exact same code as Clint in the video. Any ideas?

1 Answer

Nick Pettit
Nick Pettit
Treehouse Teacher

Hi Robert,

Typically this means that there's a missing reference in the Inspector. For example, in the CameraManager component, there's probably an Inspector field that's blank, or doesn't have the right value. Hopefully that makes sense! If you're still having trouble, upload a zip file of your project and paste the link here, I'm happy to take a look.

All the best, Nick