UI menu windows overlap

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

Hi UI menu windows overlap. How do i fix this

example When I press the character menu, it does not close to other windows

func _on_Character_pressed():
var character_menu = load("res://Data/CharacterMenu.tscn").instance()
get_tree().current_scene.add_child(character_menu)

func _on_Home2_pressed():
var home2_menu = load("res://Data/Home.tscn").instance()
get_tree().current_scene.add_child(home2_menu)

func _on_Vendor_pressed():
var vendor_menu = load("res://Data/VendorMenu.tscn").instance()
get_tree().current_scene.add_child(vendor_menu)
:bust_in_silhouette: Reply From: jgodfrey

There are any number of ways to handle this…

You’ll need to have a mechanism to manage which menu is visible. In the code you posted, you’re creating a new instance of the menu each time the associated button is pressed. If you’re going to do that, you could simply queue_free any existing menu instance(s) prior to creating the new one.

Another idea would be to simply create a single instance of each menu when the scene opens and set their visibility to false. Then, instead of creating the menus on each button press, you’d simply set the visibility of the appropriate menu to true and the visibility of the other menus to false.