Basically the title. I have a 2D game and I want to draw health bars above the player and enemies when they've taken damage.
Initially a tried to use UI components to do so, but you can't have UI entities as children of non-UI entities, which would mean that I'd need to manually position every health bar above each respective entity. Doable, but tedious.
My next attempt was to just use a couple of Mesh2d squares, one as the black backdrop and a second in front of it as the red health bar, then I just have to scale the health bar horizontally based on the percentage of health remaining. That worked but the problem was that when you scale it it scales from the center and the center was in the middle of the square resulting in the health bar shrinking towards the center instead of towards the left as I had intended. There's a few ways to work around that but once again it seemed kind of tedious to manage and potentially error prone.
I inquired in the UI channel if there was a way to use a UI component as the child of an entity and got told that I can render the UI element to a texture and then use that texture on a non-UI entity. That would work, and if I only wanted a health bar for the player that would be good enough. However since I also want health bars for all the enemies, I'm looking at rendering potentially hundreds of health bars in a worst case scenario and then trying to manage assigning the right sub-section of the rendered texture to its respect enemy. This if anything sounds even more difficult to manage than simply trying to keep the UI component following the respective entity as I would have needed to do in the first solution.
Every solution I've tried seems to have some significant drawback to it. In an ideal world I would just be able to attach the UI entity as a child of the respective player or enemy entity. So, what's the recommendation here?