• Godot HelpGUI
  • What is the intended way to construct a HUD in Godot?

I am trying to understand how HUDs are intended to be designed in Godot.

From what I can see, the design is to have you use Control based nodes; but there doesn't seem to be a (direct) way to draw part of a texture with Control based node.

Am I missing something?

You might be able to resolve the specific issue with a custom shader perhaps.

The specific issue is that I have a HUD that's composed of many tiny images, and using a TextureRect will mean dozens of tiny textures, and using a Sprite would mean losing out on some of the sizing/positioning of Control nodes.

You can draw a part of a texture using a TextureRect and setting the texture region, if I remember correctly. It will still need several TextureRect nodes, but if its all in a single image then it should render in a single draw call, so minimal performance impact.

You can also use the draw functions with Control nodes, though I'm not sure they will inherit the sizing and positioning benefits of Control-based nodes.

@TwistedTwigleg said: You can draw a part of a texture using a TextureRect and setting the texture region, if I remember correctly. TextureRect does not have a texture region.

@TwistedTwigleg said: You can also use the draw functions with Control nodes, though I'm not sure they will inherit the sizing and positioning benefits of Control-based nodes. Will these benefit from batching as well?

Maybe check out sprites? No reason you couldn't use them in combination with control nodes.

@Megalomaniak said: Maybe check out sprites? No reason you couldn't use them in combination with control nodes.

Its not necessarily an issue of solving the problem, I could always use sprites (and manually adjust their size and position) to achieve the goal, its more of a question of what is the intended (and optimal) solution?

I am trying to avoid the pitfall of solving every problem with a tool that is not intended for that purpose, if there is a tool that is.

I wasn't aware of the the draw calls for the canvas items that @TwistedTwigleg mentioned, and reading up on them they seem to be a good solution for UI/HUD's because they don't often change every frame, is this a recommended way to draw persistent HUDs?

@latreides said:

@TwistedTwigleg said: You can draw a part of a texture using a TextureRect and setting the texture region, if I remember correctly. TextureRect does not have a texture region.

Yeah, I just looked as well and, yup, it's not there. I thought it was, but I must be misremembering. You can kinda get around this using a Panel node with a textured style box, but its probably not intended to be used this way.

@TwistedTwigleg said: You can also use the draw functions with Control nodes, though I'm not sure they will inherit the sizing and positioning benefits of Control-based nodes. Will these benefit from batching as well?

I believe so, as _draw is only called once at start and then whenever you call the update function. I think it caches the result and uses that for subsequent draw calls. Though, I haven't looked into it recently and I don't remember for sure, so please take this with a grain of salt!

I wasn't aware of the the draw calls for the canvas items that @TwistedTwigleg mentioned, and reading up on them they seem to be a good solution for UI/HUD's because they don't often change every frame, is this a recommended way to draw persistent HUDs?

Probably is a decent way to draw them, though as long as your UI for your HUD isn't too complex, it probably won't have too much of a performance impact either way.

2 years later