I think there is a max capacity of 64 GUI scenes. (This could maybe turned into a setting in the future, if there are some good reasons.)
I’m guessing each of your units have their own GUI scene with one healthbar in each?
I would suggest instead you have one GUI scene with a healthbar box node and clone that one depending on how many units are visible on the screen maybe, then reposition these as the units/camera move, and update their size depending on the units healths.
For example, you could then let each unit send a message to the GUI when it moves with its new position and health. And likewise, when the unit is destroyed, send a message to the GUI to notify it can remove the healthbar.
I second Sven’s suggestion. One GUI scene for all health bars is the way to go. It’s not only better because you won’t hit the GUI scene limit, but it’s also better from a rendering perspective since you’ll be able to reduce the number of draw calls (each GUI scene will result in at least one draw call).
Thank you @sven and @britzl.
I’m changing my implementation as you suggested.
I only want to show the healthbar when the user selects a unit.
Is it more efficient to change the color to transparent when the unit is deselected or to delete and clone new healthbars every time a unit is selected/deselected?
When something is transparent, does Defold still make an effort to “draw” it, or is it ignored during rendering?
The time it takes to clone and delete nodes is not that high and it sounds as if this isn’t something you’re going to do it every frame. Still, I would suggest that you enable/disable the nodes instead using gui.set_enabled() instead of setting alpha to zero.