Whats an efficient method for drawing hundreds of Health Bars etc. over units for an RTS?

That’s the whole question really, I have been using:

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

In the UI elements update event, but it slows down a lot with just that line, once you have 20-30 units. I’ve tried putting them all on one canvas, and giving each a seperate canvas, but it appears to be the WorldToScreenPoint function causing the slowdown.

There’s no real way to call this less than in Update either, at in addition to the unit moving (which you could dead reckon a bit) the screen position and zoom level may change.

Any ideas? This must be have been solved before?

I can’t say I know for sure what the most efficient approaches are, but I can tell you one thing: The GUI is spectacularly inefficient.

My first thought would be to use 3D objects (planes) with a billboard shader for a baseline. With this, you can have a baseline to work from. From there, some tweaks to initial sizing and general re-scaling of parts should make for reasonably usable health bars.

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.