_Input vs InputEvent, and recieving an InputEvent from the same object that called it

Godot Version

4.5.1

Question

Hi, I’m trying to detect mouse movements and clicks on an Area3D. I have some questions about how exactly input, _Input(), and the InputEvent signal work (I’d rather not use polling).

If I use the _Input() event, it seems to trigger every time the mouse moves regardless of whether or not the cursor was over the Area object.

public override void _Input(InputEvent @event) {
    GD.Print("Detected input!"); // fires every frame the mouse moves
}

On the other hand, I can connect to the InputEvent signal that the object raises.

public override void InputSignalReciever(Node camera, InputEvent @event, 
    Vector3 eventPosition, Vector3 normal, int shapeIdx) {
    GD.Print("Detected input!"); // only fires when mouse is over Area3D
}

This has the advantage of including extra information about the input, and only fires when I want it to. But as far as I can tell, the only way to actually access it is to connect the object to itself using the Signal UI in the inspector.

I have a few questions:

  • Am I understanding this correctly?
  • Why does _Input() fire all the time, but the similarly-named signal only fires when the mouse is over the object?
  • Is it possible for the object’s own code to listen for its own signals without having to use the inspector to reroute it to itself? It’s not really a big deal if I have to do that, it’s just a bit weird.

I think some of my confusion here is the way the documentation/tutorials are worded – they don’t always distinguish between the InputEvent Signal and the InputEvent object, or how to receive either of those things.

Check the documentation about how InputEvents work:

You don’t need to use the editor. You can use Signal.connect() in GDScript like: $Area2D.input_event.connect(_on_area2d_input_event) For C# you can check the documentation:

1 Like