+1 vote

I've been trying to figure out the syntax to do that.

Does anyone know how to
Add new items to a submenu?
Add another submenu to a submenu??

How exactly do you operate on submenus?
Get_node? How?

in Engine by (94 points)

1 Answer

+3 votes
Best answer

Here's some sample code that adds a submenu and a sub-submenu to the PopupMenu of a MenuButton:

extends MenuButton

var popup
var submenu = PopupMenu.new()
var subsubmenu = PopupMenu.new()

func _ready():
    popup = get_popup()

    subsubmenu.set_name("subsubmenu")
    subsubmenu.add_item("Sub-submenu item a")
    subsubmenu.add_item("Sub-submenu item b")

    submenu.set_name("submenu")
    submenu.add_item("Submenu item a")
    submenu.add_item("Submenu item b")
    submenu.add_child(subsubmenu)
    submenu.add_submenu_item("Sub-submenu", "subsubmenu")

    popup.add_item("Item a")
    popup.add_item("Item b")
    popup.add_child(submenu)
    popup.add_submenu_item("Submenu", "submenu")

To check which item the user clicks use the item_pressed signal. You'll probably want to connect each submenu to a separate function.

by (1,540 points)
selected by

Hi,
thank you for the answer. In your example, how do you delete all the submenus before creating them?
Basically I need to reset them every time the menu button is clicked - I want to make submenus populate dynamically every time the button is clicked

My ultimate goal is the get a folder structure and turn it into a submenu structure to access directories of subfolders. It's turning out to be very challenging :o

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.