1
\$\begingroup\$

TLDR: Calling coroutines from OnValidate in edit mode leads to following error:

Assertion failed on expression: 'ShouldRunBehaviour()'
UnityEngine.MonoBehaviour:StartCoroutine (string)
script:OnValidate () (at Assets/script.cs:12)

Code (simplified to recreate error from main project):

public class script : MonoBehaviour
{
    public int number;

    private void OnValidate()
    {
        StartCoroutine("coroutine");
    }

    IEnumerator coroutine()
    {
        print(number);
        yield return null;
    }
}

Long version:

Making a background generator for TextMeshPro using "Shapes" plugin. Must work in both edit mode and play mode. For reasons, TextMeshPro.textBounds is not updated until the frame after the one you set the actual text. So setting the background in that frame gives you the dimensions for the previous frame's text.

I don't want to set the new dimensions every frame, but a coroutine with WaitForEndOfFrame fixed the issue. However I get the assertion error in the editor.

Thanks for any help.

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.