Interface elements (dialogs on top of each other)
Warning
The "Interface element" behavior is available starting from the next version of GDevelop. It's not available in the current version yet.
Menus, dialogs, shops and HUDs are drawn above the game, and dialogs are often opened above other dialogs: a "Settings" dialog opened from the pause menu, a confirmation opened from a shop... The Interface element behavior makes sure that only the interface drawn on top reacts to the player:
- A click or a touch on a dialog doesn't also trigger the button, the dialog or the game object that is under it.
- Only the dialog opened last reacts to the keyboard and the gamepad: Escape closes it, and not all the dialogs at once.
- When it's closed, the dialog under it reacts again.

This page explains the two ideas behind it: blocking the pointer and the keyboard and gamepad focus. Most of it is useful when you build your own interface as a custom object. If you only use the dialogs, shops and buttons of the asset store, they already handle this: you can skip to Use the dialogs of the asset store.
Block the pointer
The pointer is the mouse cursor or a finger on a touchscreen. An object with the "Interface element" behavior blocks the pointer: the objects drawn under it don't react to the clicks and touches where it is, as if it was a sheet of paper put on them.
An object is drawn above another one if it's on a layer that is above, or on the same layer with a greater Z order. Objects inside a custom object are compared through the custom object containing them: all the children of a dialog are above a button of the scene if the dialog is above the button.
These conditions and behaviors take it into account:
- The condition The cursor/touch is on an object ignores the parts of the object that are covered by the interface. Use it in your events and the click on a dialog won't reach the object under it.
- The buttons, sliders and other interface objects of the asset store aren't hovered, pressed or clicked when they are covered.
- An object with the Draggable behavior can't be dragged from a covered part.
- A text input can't be clicked or touched when the interface is drawn above it.
Tip
A dialog never blocks its own buttons: the objects inside a custom object are not covered by the custom object, or by the other objects inside it drawn under them (like the background panel of the dialog).
Block everything under a dialog with an overlay
To make sure that nothing at all can be clicked while a dialog is opened, add an overlay: a sprite covering the whole screen (often black and semi-transparent, to darken the game), with the "Interface element" behavior. Put it just under the dialog, with a Z order smaller by one than the one of the dialog, and hide or delete it when the dialog is closed.
Without an overlay, only the area of the dialog blocks the pointer: the buttons around it can still be clicked. Both can be useful: a pause menu usually has an overlay, while a small notification panel in a corner usually doesn't.
Ignore the clicks on the interface in the gameplay
In many games, a click or a touch anywhere does something: shooting, moving the character, placing a building... Use the condition The cursor/touch is on an object blocking the pointer (inverted) in these events, so that a click on a button of the HUD or on a dialog doesn't also make the character shoot.
The keyboard and gamepad focus
Unlike the pointer, the keyboard and the gamepad have no position: something must decide which dialog reacts to them. This is the focus.
Enable Modal in the behavior of a dialog: when the dialog is shown, it takes the focus. When another modal dialog is shown above it, this one takes the focus. When it's closed (hidden or deleted), the focus goes back to the previous dialog. This works for any number of dialogs opened above each other, without any event to write.
- Use the condition Has the keyboard and gamepad focus in the events reading the keyboard or the gamepad. It's true for the dialog having the focus and for the objects inside it, and for all objects when no dialog has the focus.
- The default keyboard controls of the Platformer character and Top-down movement behaviors pause while a dialog has the focus: the character doesn't jump when Space confirms a choice in a dialog.
Note
The focus tells which dialog reacts. Which button is selected inside the dialog is up to the dialog itself: for example, it can select its first button when it gets the focus, as explained below.
Make your own dialog with a custom object
A dialog made as a custom object usually has a background panel and some buttons inside it. To make it an interface element:
- Edit the custom object, and add the "Interface element" behavior to its background panel (a child object).
- Enable Modal and Give focus to the parent custom object: the whole dialog, with all its children, gets the focus, and not only the panel.
- In the events of the custom object, put the events reading the keyboard and the gamepad (like the arrows to choose a button, Enter to confirm and Escape to close) as sub-events of an event with the condition Has the keyboard and gamepad focus on the custom object itself (the
Object). - Use the condition Just gained focus of the behavior to select the first button when the dialog is opened. When a dialog opened above it is closed, the dialog gets the focus back: it can keep the button that was selected before.
That's all: the panel blocks the pointer for everything under the dialog, and the buttons of the dialog are not blocked by their own panel.
Tip
Use the condition The cursor/touch is on an object on the children of the custom object (like the items of a list) rather than comparing the position of the cursor: it ignores the parts covered by another dialog.
Use the dialogs of the asset store
The dialogs, shops and buttons of the asset store are already interface elements: their panels are modal and block the pointer, and their buttons ignore the clicks when they are covered. In your scene, you only have to:
- Create each dialog above the previous ones, with a greater Z order (or on a layer above).
- Delete or hide a dialog when it's closed.
The Interface playground example opens up to 40 dialogs of different kinds above each other, with an optional overlay, to try it with the mouse, touches, a keyboard and a gamepad.