I feel very silly for posting what appears to be a very simple bug but I’m seriously just stuck. I cannot fix this persistant NullReferenceException. This is my simplified test case.
if (gameCamera = null)
print(“No game camera found”);
print(gameCamera.transform.position);
At the moment I get the Null reference exception on the last line (as soon as I try to access “gameCamera”) but I don’t get “No game camera found” being printed - which seems impossible to me. What obvious thing am I overlooking?
= != ==
In other words, it should be
if (gameCamera == null)
What programming software are you using? I strongly recommend Visual Studio Express (free!) because it catches silly mistakes like this.
Doh! I keep doing that.
I’m using monodevelop, which catches most things. Thanks for the incredibly quick reply.
What’s really funny is that the Null reference exception was actually being caused by my broken check. I was setting the gameCamera to 0, just before trying to access it. If I’d removed the “check” altogether, it would have worked fine.