UiElement created at runtime is not displayed.

I created a uielement and gameobject in the runtime and set it to follow the world position of the gameObject.

public void LateUpdate()
{
    var position = gameObject.transform.position;
    var newPosition = RuntimePanelUtils.CameraTransformWorldToPanel(gage.panel, position, Camera.main);

    gage.transform.position = new Vector2(
        newPosition.x - gage.layout.width * 0.5f,
        newPosition.y
    );
}

but the uielement is not displayed.

I’ve tried a few things and found a way to display them.

  1. Change the LateUpdate function to Update and it will be displayed.
  2. Select Element from the UI toolkit debugger and change the style and it will be displayed.
  3. Change the element style elsewhere than the function that generated the uielement at runtime and it will be displayed.
  4. Following objects already created in the scene works correctly.

Why is this happening? How do I display elements correctly?

It seems to be a bug that only occurs when an object is created within the event function registered as RegisterCallback. Can anyone tell me a solution?

When creating a visual element using RegisterCallback, the layout value was not properly applied in the first frame of LateUpdate (Nan).

However, in the class update function that inherited Mono, I created a visualElement when Input.GetMouseButtonUp(0) and the layout value was applied correctly.

I wrote down this code as a temporary measure and corrected it.

if (float.IsNaN(gage.layout.width))
{
    return;
}

Is there a way to apply the layout value correctly when creating element using RegisterCallback?