The PopupMenu does not pop up in the area of CharacterBody2D

Godot Version

4.2

Question


I am working on a small game. The game has objects troop and city. In the troop, I use MOUSE_LEFT to trigger a popup menu. The popup menu is the mouse position.

The most relevant code:

func _unhandled_input(event: InputEvent) -> void:	
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT:
			var target = get_global_mouse_position()
			if event.pressed:				
				if selection_node.selected:
					#print("set target %s" %[target])
					set_target_position(target)					
					popup_menu.set_position(target)					
					popup_menu.popup()					
					print("debug: popup menu %s"%[target])																			
							
			else:
				pass	

There are two cases
case 1: mouse position is on a tilemap
case 2: mouse position is inside an object (city).

It works well in case 1. However, the the PopupMenu does not appear in case 2. The debug message shows the popup_menu.popup() is called but I can not see the menu.

I have some guess here:
1: The PopupMenu is behind the city? I tried to click the mouse in the edge of the city, I can not see part of PopupMenu.
2: The city is selectable. So, the MOUSE_CLICK used by the city but not pass to the troop? Because the debug message shows the popup_menu.popup() is called. So the mouse event is passed to the troop.

Thanks.

You know the input event mouse will also have a mouse position too.

Thanks for putting the .mouse_get_position function. I have tried that in the var target = get_global_mouse_position() var target_2 = DisplayServer.mouse_get_position() print("target ", target) print("target 2: ", target_2)

In my case, the target gives the correct position in window because the target_2 gives the coordinate in the display.

I guess may from the setting of the city. The left_mouse_click are used in two places. 1: trigger the popup menu; 2. select the city.


In this screenshot, the city is selected with I click the left mouse.

This is the scene tree in the code
scene_tree

The popup menu works when the mouse is on the TileMap. It does not work on the city and another unit.

Ah, I misread your question.

So there are settings on the project to embed Sun windows, (popup menu is a window). If these are all set properly then the menu is probably being set to the canvas layer of your parent where it is added.

I guess you should have the parent, that creates a popupMenu, be on a canvas layer above everything else.

Thanks for the follow up. Confirmed that the embed subwindow is on.

In my case, the troop_unit node is the parent node of the popup_menu

Then, I set the “Top Level” on in the troop unit node.

However, the popup menu is still not visible.

That seems right

Tilemap also has layers maybe there is an issue there