How to create UI in Godot: Core Concepts (part 1)

Hi there! This is a short introduction about how to make user interfaces in Godot, from main menus, inventory systems, game HUD and more, while keeping it responsive for different screen resolutions.

0:00
/0:18

This post is the start of our own learning notes on Godot (we'll release multiple ones!), and we also genuinely love UI so we hope we'll make it easier for you as well.

Core concepts

In Godot all UI elements are subclasses of the "Control" node.

This includes Buttons (to handle click/mouse pressure), Labels (to display text), Progress Bars (to display a percentage) and much more.

0:00
/0:08

where to find control nodes in Godot

At first, all control nodes are placed in a rectangle that's as big as the game resolution.

the rect (slight blue) of the game resolution

In Godot, the origin is in the upper left corner of the screen and Y is down.
(Sigh for multi-engine users)

Position and Size

Every Control node has position and size properties, which describe their presence on the screen.

0:00
/0:13

Anchors

If we want to make a responsive UI (in other words: scaling based on different resolutions), then we want to link/constrain (or "anchor") a Control node based on its parent (you can think of the very first parent as the screen size/viewport), so that when something changes, our nodes also change correctly.

You can set a Control node anchors in a few ways. The quickest one (and what you'll probably use most of the time) is accessed at the top of the scene view.

0:00
/0:08

How different anchors modify and relate to a Control node's settings

The anchors icons/templates can be interpreted in two ways:

  • if the icon is "fixed", then you're anchoring the pivot of a node to its parent/container.
  • if the icon is "filled" (from one side or both), then you're also controlling its dimensions based on the parent.
0:00
/0:10

how "fixed" or "fill" anchors change objects proportions

You can also set anchors manually via code, the inspector or the scene view/gizmo, to better control how an object resizes in the scene. If all the anchors are in the same spot, then it counts as "fixed" and you're only controlling the movement. If two or more anchors are away from each other, then you're also resizing based on their distance (if it's too far, then it will scale/change a lot, and vice versa)

0:00
/0:16

setting anchors manually

Note: Godot used to mention "margins" up until a previous version (4.3??), but they're now referred to "Anchor Offset". We didn't mention them yet to introduce things more clearly, but just know that you can decide precisely how many pixels you want a control node to "stay away" (or closer) to its container, when resizing dynamically. This value is relative to the anchors ("fixed" vs "fill etc."), and it's set for you automatically when you use the icons/templates we talked above.

Control node inspector

Now that you know how to resize elements, you could theoretically complete your full UI this way, but you'd find yourself having to set a lot of options manually and it would become a messy project really fast, especially if you have a lot of elements (or lists).

Using Containers

Godot provides a set of nodes called Containers, which automatically arrange children elements for you (based on specific layouts and settings).

0:00
/0:07

adding control nodes

Containers can follow different layouts, like "Horizontal" (e.g. placing all elements next to each other on the same row), "Vertical" and so on, and you can also decide how to distribute them (if starting at the center, beginning or end)

0:00
/0:06
👍
If you want/prefer, you could even build a full UI using only nested containers.

PSA you might want to set a "minimum size" to your children nodes, since containers have no way to know how big an object should be.

control node "custom minimum size" settings

In Conclusion

Here it ends part one about the core concepts of UI / Control nodes in Godot. It's all that is needed (in our opinion) to begin playing with the other building blocks (the actual elements that display information) like Buttons, Labels and much more, to create a responsive UI for your games/projects. Here is a list of common nodes from the Godot documentation.

That said... it doesn't end here! We'll share part 2 in the next weeks continuing with signals, themes, animations and more, so that you can go from start to finish and achieve what you want.

Thanks for reading through here (please consider supporting us, so that we can continue doing it) and hear you soon!

(P.S. The UI pack we've used, except for the background, is from Kenney's! You can download it here.)

Febucci

Help us stay independent! [for free]

Make sure you never miss other content and help us stay independent and keep posting what we love. It's free! ❤️

Never miss any new post, from games, tools and what we notice in the industry in general
Our Unity, Godot, Game Art and Design learning notes
Help us reach you even if social medias change algorithms, die, AI takes over and suddenly no one knows what's real anymore..
Already have an account? Sign in

Deep dive

Almost five years ago I released a plugin called “Text Animator for Unity”, a tool I made/needed for my own games - and Today it is also getting used in other games like “Dredge, Cult of The Lamb”, “Slime Rancher 2” and many more!! I’d love if you could check it out! you’d also support us with this blog and new assets! ✨

Product callout image

Thanks so much for reading!