Can I handle InputEvent of a node in another node?

Godot Version

Godot v4.3.stable.mono

Question

Is it possible to handle/connect to an InputEvent of a specific node in another node without doing any workarounds where the input in specific node is overrided?

Of course I can make an event and just invoke that, but I’m wondering whether there is a godot way that solves it which didnt know of.

No, there is currently no such functionality. If you want to act on an InputEvent in a specific node, then this specific node needs to implement how to act.

What? Of course you can do that, unless I’m fundamentally misunderstanding what you mean.
You can make a custom signal on your original mode, to which you can connect from another node.
You can have a reference to another node in your original node and make calls to your other node directly from your original node.

Worth noting is that InputEvent is usually triggered from a viewport, not a node. So the same InputEvent will be propagated to all your Nodes and can be handled everywhere the same.

If you share a bit more details about what your trying to achieve I may be able to help you more specifically, if you need some more guidance.

1 Like

Maybe an XY Problem, what are you really trying to do?

1 Like

Basically I was asking if there is a way to connect the input event from a node without overriding _input(), it seems to me that the only way is to override the _input and invoke a event or signal inside the _input

I tried some things, CollisionObjects have InputEvent that can be used without overriding _InputEvent so I’ll use that, but still other nodes I guess you can’t handle inputs without overriding the _input function and calling some event from there

You can use Input singleton class and call it in _process() method, or any other

E.g.

if Input.is_action_just_pressed("action"):
    # do something

Apparently, I misunderstood you, sorry.

Without overwriting _input() or _unhandled_input() or any of the other input event functions, that are available for nodes, you can connect to the following signals , that are provided by specialized nodes, in order to get notified, when a different node receives an InputEvent:

Here is a complete overview:

1 Like

Yes exactly, I was looking at wrong nodes which didn’t have those signals, but later I tried other nodes which did have it.

Now that I think about it more, it makes sense that CollisionObjects and Control nodes would have those signals :sweat_smile:

Thank you for the image and explaining.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.