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.