+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?

asked Aug 18, 2017 in Engine by blurymind (90 points)

1 Answer

+1 vote
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.add_item("Sub-submenu item a")
    subsubmenu.add_item("Sub-submenu item b")

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

    popup.add_item("Item a")
    popup.add_item("Item b")
    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.

answered Aug 19, 2017 by mollusca (1,506 points)
selected Aug 21, 2017 by blurymind

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.