Questions about the property Button in ProgressBar and Odin in Unity

Issue #384 new
Former user created an issue

I use the Button property to write a program to load resources, using the progress bar in Unity. Although there are no problems with the results, there will be 3 error messages. I hope to solve this problem.

using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;

public class _Test : MonoBehaviour
{
    [Button]
    void OnClick()
    {
        for (int i = 1; i <= 999; i++)
        {
            //One
            var isCancle = EditorUtility.DisplayCancelableProgressBar("Loading......", "i = " + i, i * 1f / 999);
            if (isCancle)
                break;

            //Two
            //EditorUtility.DisplayProgressBar("Loading......", "i = " + i, i / 999);
        }
        EditorUtility.ClearProgressBar();
    }
}

Using the first progress bar will result in an error, but the second progress bar will be safe.

Comments (2)

  1. mSkull001

    This is happening due to various state changes in IMGUI code. The errors themselves are harmless and can be ignored.

    It is possible that this has been resolved in the 2.0 patch, but for now, you can probably get around it by delaying the method call with EditorApplication.delayCall:

    [Button]
    void OnClick()
    {
        EditorApplication.delayCall += OnClickDelayed;
    }
    
    void OnClickDelayed()
    {
        ...
    }
    
  2. Log in to comment