Whats the most efficient method for placing UI elements at world positions? (Above units etc.)

I need to draw GUI elements above buildings and units for an RTS.
I’ve seen the method being used:

rectTransform.position = Camera.main.WorldToScreenPoint(unit.transform.position);

Using the screen space overlay canvas render mode.

When implementing this, it seems very performance hungry, and needs to run in update to remain accurate when scrolling the viewport or for moving units.

So my question is, is there a more efficient way to do this?

Well I can mark this as solved. It turns out calling Camera.main essentially searched for the camera tagged appropriately every time and is INCREDIBLY slow.

Caching the main camera in a public field of a manager class fixed the problem completely.

This approach seems fine.

As Baste said you should profile first. But what you need to consider is the cost of moving an UI object. When you move just one object in a Canvas it reconstructs its internal mesh representation. So you at least should move dynamic objects to a separate Canvas. Probably it would be a good idea to have a separate Canvas for every unit UI.

You also can try using World Space UI and prerendering unit UI into a texture if it doesn’t change much.