Null Reference when trying to use main Camera position

I am receiving a Null Reference Exception when trying to use Camera.main.transform.position as the source of my audio (Note: transform.position works perfectly fine)

printing Debug.Log(Camera.main) returns Null. So somehow I must have removed the ‘main’ reference on my camera.

Where do I tell Unity that a Camera is the main camera? Will attach my main camera settings below

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring.

If the line of code tries to access Camera.main, make sure that your camera has got the Main Camera tag. According to your screenshot, it has got the “Untagged” tag.

Did this help?


See also:

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

Privacy & Terms