I noticed a strange crash bug while developing my project. I have several identical objects in the hierarchy.
Each object has a simple script. Here it is: Code
using UnityEngine;
public class SimpleObject : MonoBehaviour
{
public float property;
private void OnValidate()
{
foreach (var obj in FindObjectsOfType<SimpleObject>())
{
// null check doesn't helps
if (!obj || !gameObject)
{
Debug.Log("NUll");
return;
}
// without this if everything works fine
if (transform.position.z > obj.transform.position.z)
{
// do something
}
}
}
}
Also, I have an object, that reload scene by click.
Code
using UnityEngine;
using UnityEngine.SceneManagement;
public class ReloadSceneOnClick : MonoBehaviour
{
private void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Debug.Log("Reload Scene");
SceneManager.LoadScene(0);
}
}
}
When I enter playmode, click to reload the scene and try to exit playmode, unity crashes. This happens with both Unity 2019.4.4 and Unity 2019.3.13. I have already reported a bug. Do you have any ideas why it happens?