Search Unity

Unity Editor crash when exit playmode

Discussion in 'Editor & General Support' started by flypew1, Jul 17, 2020.

  1. flypew1

    flypew1

    Joined:
    Mar 28, 2020
    Posts:
    2
    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 (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SimpleObject : MonoBehaviour
    4. {
    5.     public float property;
    6.  
    7.     private void OnValidate()
    8.     {
    9.         foreach (var obj in FindObjectsOfType<SimpleObject>())
    10.         {
    11.             // null check doesn't helps
    12.             if (!obj || !gameObject)
    13.             {
    14.                 Debug.Log("NUll");
    15.                 return;
    16.             }
    17.            
    18.             // without this if everything works fine
    19.             if (transform.position.z > obj.transform.position.z)
    20.             {
    21.                 // do something
    22.             }
    23.         }
    24.     }
    25. }
    26.  

    Also, I have an object, that reload scene by click.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class ReloadSceneOnClick : MonoBehaviour
    5. {
    6.     private void Update()
    7.     {
    8.         if (Input.GetKeyDown(KeyCode.Mouse0))
    9.         {
    10.             Debug.Log("Reload Scene");
    11.             SceneManager.LoadScene(0);
    12.         }
    13.     }
    14. }
    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?
     

    Attached Files:

  2. flypew1

    flypew1

    Joined:
    Mar 28, 2020
    Posts:
    2