Menu item cannot be clicked, bug or expected behaviour?

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

I have found something that maybe a bug or just a lack of experience on my part. I have simplified at maximum the problem.

I have the following scene:

Node2D
    |--> PopupMenu

In the root node (Node2D) I have the following code:

extends Node2D

func _input(event):
	if event is InputEventMouseButton:
		if event.pressed:
			Input.set_default_cursor_shape(Input.CURSOR_DRAG)
			pass
		else:
			Input.set_default_cursor_shape(Input.CURSOR_ARROW)

In the second node (PopupMenu) I have this code:

extends PopupMenu

func _ready():
	add_item("item a")
	add_item("item b")
	add_item("item c")

	connect("id_pressed", self, "_on_item_pressed")
	popup()

func _on_item_pressed(id):
	print(get_item_text(id), " pressed")

Nothing else. No more config in a standard Godot 3.1 project.

Now, if I run the project, I see the popup menu in screen, but if I click to any of the items nothing happens (print is never executed).

In order to get print running I have to comment or remove the line Input.set_default_cursor_shape(Input.CURSOR_DRAG) in “Node2D.gd” and then the result is the expected with the print showing the option selected.

Why is this happening?

(Of course, this program has no sense, that’s just a simplification of my real program).

I’m a little confused about your code but I do know this you do not need pass in that code. Pass is mostly for debugging, what pass does is it tells the computer that if there is a error in the place to simply keep going along the code and ignore it.

Merlin1846 | 2020-04-05 14:38

Yes @merlin1846, I have left the pass just to put a comment at the previous line for debugging purposes (the code itself is just a minimum test with the problem I observed, my real code is much more complex)

navi2000 | 2020-04-05 18:01