here are some pretty simple lines of code, that throw a NullReferenceException
. Since I get the exception via CloudDiagnostics I don't know which line threw the exception, but only which method.
private void DestroyChest() {
if (Chest != null && Chest.gameObject == null) {
Debug.LogException(new Exception("Chest.Gameobject is null!"));
}
Destroy(Chest?.gameObject);
}
Chest
is a MonoBehavior
script. And nowhere is a property accessed without checking it first.
Now my question is. Why and how do I get a NullReferenceException
.