Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

(Case 1155938) Using EditorUtility.DisplayCancelableProgressBar in ChangeCheckScope makes errors

Discussion in '2019.2 Beta' started by Kichang-Kim, May 20, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,025
    Hi, I found that EditorUtility.DisplayCancelableProgressBar() in custom inspector makes some errors.

    Here is reproducible code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Threading;
    4. using UnityEditor;
    5. using UnityEngine;
    6.  
    7. [CustomEditor(typeof(MyComponent))]
    8. public class MyComponentInspector : Editor
    9. {
    10.     public override void OnInspectorGUI()
    11.     {
    12.         base.OnInspectorGUI();
    13.  
    14.         using(var changeScope = new EditorGUI.ChangeCheckScope())
    15.         {
    16.             EditorGUILayout.PrefixLabel("Test Box 1");
    17.  
    18.             using(new EditorGUILayout.VerticalScope("box"))
    19.             {
    20.                 if(GUILayout.Button("Test Button"))
    21.                 {
    22.                     this.SomeHeavyWorks();
    23.                     Debug.Log("Test Button clicked.");
    24.                 }
    25.             }
    26.  
    27.             EditorGUILayout.PrefixLabel("Test Box 2");
    28.            
    29.             using(new EditorGUILayout.VerticalScope("box"))
    30.             {
    31.                 if(GUILayout.Button("Test Button"))
    32.                 {
    33.                     this.SomeHeavyWorks();
    34.                     Debug.Log("Test Button clicked.");
    35.                 }
    36.             }
    37.  
    38.             if(changeScope.changed)
    39.             {
    40.                 Debug.Log("Changed Scope Changed.");
    41.                 SceneView.RepaintAll();
    42.             }
    43.         }
    44.     }
    45.  
    46.     private void SomeHeavyWorks()
    47.     {
    48.         EditorUtility.DisplayCancelableProgressBar("Work", "...", 0.0f);
    49.  
    50.         Thread.Sleep(250);
    51.  
    52.         EditorUtility.DisplayCancelableProgressBar("Work", "...", 0.25f);
    53.  
    54.         Thread.Sleep(250);
    55.  
    56.         EditorUtility.DisplayCancelableProgressBar("Work", "...", 0.5f);
    57.  
    58.         Thread.Sleep(250);
    59.  
    60.         EditorUtility.DisplayCancelableProgressBar("Work", "...", 0.75f);
    61.  
    62.         Thread.Sleep(250);
    63.  
    64.         EditorUtility.ClearProgressBar();
    65.     }
    66. }
    67.  
    (MyComponent can be any Monobehaviour types.)

    Above code generates errors like this:
    Reproducible projects is sent as Case 1155938.
     
    LeonhardP likes this.