Input Event Help

Godot Version

4.3 Stable

Question

Hey there I am trying to make a window appear when I press the left mouse click on some of the buildings but so far it doesn’t register anything.

func _on_tower_body_area_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	print(" INPUT DETECTED ")
	if event is InputEventMouseButton:
		if Input.is_action_just_pressed("Left_Click"):
			print(" INPUT 2 DETECTED ")
			var tower_screen = get_node("TowerStatsScreen/Panel")
			if tower_screen.visible:
				tower_screen.hide()
			else:
				tower_screen.show()
			print(" TOWER CLICKED ")

It just doesn’t detect the event it seems at all since none of the print commands activate.

Screenshot_2

This is my node setup and the TowerBodyArea has the event signal added to it but somehow it doesn’t work. Read on the forums about the input event and tried a few variations of it but with no luck.

It does require “input_pickable” to be true (this is default on for Area2D) and at least one collision layer set. Is there any UI that may get in the way? Even a blank Control node could stop the mouse input.

I have the static body as a pickable and the TowerBodyArea has a collision layer added to it.
I haven’t checked about the control nodes since I do have an UI on the scene, will give it a try now.

Ah, the static body doesn’t have any collision shapes, so it has no collision thus no way to click it. You might not want a static body for this either if you have been ignoring it’s warning this long.

You were right the issue was with the control node from the HUD display. When I made it invisible the input event printed succesfully. But how can I go around this issue now if the control node is the issue? Should I increase the order of the tower area body?

Well I use the Static Body and add an Area2D on it with the collision layer, won’t that work as well?

You can set the control node to Pass or Ignore mouse input, this is the mouse_filter property.

The static body does not inherit it’s children’s collision shapes, that would be chaotic! Your range would also be a blocking body if that were the case, and not very useful. A Static body has it’s own collision layers and masks so how would it use the child Area2D’s collision layers and masks? replace it’s own? merge the two? what would a merge look like?

For all these questions to answer it’s much easier and sensible to program the engine to only look at it’s direct child collision shapes.

So your Static Body has done nothing this whole time, if that hasn’t been an issue, try changing it to a Node2D instead.

Thanks I will give it a try for sure and test it out to see how it turns out so I will still be able to interact with some of the buttons on the UI while also being able to interact with the tower.

I also wondered about the StaticBody collisions but I just set up the area2d collisions of that, still really new and learning about everything for Godot. Thank you for this great tip so I can be on the right track going forward i really appreciate it.

1 Like