So, I have a scrip that is attached to a Camera Game Object.
Here’s code:
private void Awake()
{
mainCamera = GetComponent<UnityEngine.Camera>();
}
private void OnCameraZoom(float amount)
{
mainCamera.orthographicSize = Mathf.Clamp(mainCamera.orthographicSize - amount * Time.deltaTime, config.MinZoom, config.MaxZoom);
}
And here’s funny thing - everything works fine in the Editor and in the Windows Build, but in Android build I get Null Reference exception, because mainCamera
is null. Like, whaaaaat?
While debugging I found this message (sadly enough logcat didn’t gave me this message and I’m having troubles with building dev build with script debugging):
MissingReferenceException: The object of type 'Camera' has been destroyed but you are still trying to access it.
Ok… But what? How? Why does it work on Windows build and in the Editor?
I’ve found a temporary solution, like using Camera.main
if mainCamera
is null, it works, but jeez.
Is this some sort of bug?