Trying to add Image for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported.

I’m trying to change the position of an Image in OnPopulateMesh, but I get this error:
“Trying to add GameObject (Image) for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported.”

I’ve tried moving the code to avoid the error, but OnPopulateMesh is where it should be. It works correctly, and it’s not in an update loop. Is there anything I can do to disable the error? Is there a function that behaves like OnPopulateMesh (only called once when the object changes) that I could use instead? GraphicUpdateComplete was the most promising thing that I found, but it still generated the same error.

Thanks :slight_smile:

I got the same error when Disabling a TextMeshProUGUI component in OnRectTransformDimensionsChange if it is the child of a layout group.

While simply disabling logging seemed to work, I managed to circumvent the error entirely by waiting for the rebuild to finish in a Coroutine.

protected override void OnRectTransformDimensionsChange()
{
	if (!gameObject.activeInHierarchy) return;
    
    StartCoroutine(ChangeLayout());
}
    
private IEnumerator ChangeLayout()
{
	while (CanvasUpdateRegistry.IsRebuildingLayout())
	{
		yield return null;
	}
	....   
}

Disabling the error is easy:
Debug.logger.logEnabled = false;

Does anyone have a proper solution to this problem, though?