How to enable/disable items in a popup menu in code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All. I have a popup menu with a bunch of items. I want them to pop up as enabled or disabled depending on some conditions in the game (eg, can’t build a table if you don’t have wood in your inventory). How do I access the popup menu’s items’ properties in gdscript?

:bust_in_silhouette: Reply From: njamster

Use set_item_disabled(<item_id>, <bool>). Here’s an example:

extends PopupMenu

func _ready():
    # add three items to the PopupMenu
	add_item("Test1")   # id: 0
	add_item("Test2")   # id: 1
	add_item("Test3")   # id: 2

    # disable only the second item,
    # the rest will be enabled by default
	set_item_disabled(1, true)

	popup() # show the PopupMenu

Is there a way to completely remove them from the menu instead of just greying them out?

blurrred | 2021-12-17 07:09