Search code examples
mousegodot4

How to check for mouse click on Area2D in Godot 4?


How do I detect mouse clicks/mouse events in an Area2D's script? Do I use the func _process(delta) function? Let's say I have an area 2D called area. So what should the script be like? I want something like this:

extends Area2D


func _process(delta):
    if mouse_touching && mouse_left_down:
        print("clicked on object")

Solution

  • If your Area2D has input_pickable then it will get a call to _input_event when the user clicks it.