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.
- Change the LateUpdate function to Update and it will be displayed.
- Select Element from the UI toolkit debugger and change the style and it will be displayed.
- Change the element style elsewhere than the function that generated the uielement at runtime and it will be displayed.
- Following objects already created in the scene works correctly.
Why is this happening? How do I display elements correctly?