Cannot get Resolved Height

Hi,

I cannot get resolved height of a visual element on start/OnEnable. This is something I will have to do a lot for placing elements off screen.

I know you can do it if you wait a frame or two, but this seems like a workaround.

Just curious if this will change or is this the official way to do it, using a Coroutine private IEnumerator Start() to wait a frame before doing all these calculations?

Thanks!

This will indeed remain an asynchronous process but we may expose a way to force layout to happen synchronously.

In the meantime the most straightforward way to do this is to listen for GeometryChangeEvent on the element you’re interested.

1 Like

Got it, thanks!

Should I then not use WaitForEndOfFrame() in start and use that callback instead? Just curious in case my method has some disadvantages such as not working 100%? Or will my method work 100% of the time?

Thanks!

I think it will work 100%. It’s just that this GeometryChangedEvent is managed by UI Toolkit and works even in the editor, while the WaitForEndOfFrame() & coroutines are Unity wide constructs.
Effectively layout should be processed between Update() and LateUpdate() so end of frame is safe.

1 Like

Perfect, thanks!