Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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