Input order confusion.

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

I have a character node with Area2D receiving _input_event.
Below that I have a tilemap receiving _unhandled_input.

How do I make the character node run first. I’ve tried moving the nodes around, and it seems like _unhandled_input always runs before it.

Sample log:
[InputEventMouseButton:1312] Map False
[InputEventMouseButton:1312] Guy True

The bool at end is just is_input_handled() at end of function.

I’m doing this in GDScript.

:bust_in_silhouette: Reply From: markopolo

Looking at the InputEvent Docs, that seems to be expected behavior. The order in which input is handed out to various nodes is as follows:

  1. _input
  2. Control._input_event
  3. _unhandled_input ← your tilemap
  4. CollisionObject._input_event ← your Area2D

If you want the Area2D to get events before the tilemap, the simple fix is to change the Area2D to use _input instead of _input_event, although depending on what else in your app listens for inputs it might get more complicated than that.

As a reminder, make sure you’re using accept_input or set_input_as_handled or whatever as appropriate if you don’t want the event to get handed out further down the list.

problem is _input() is called on all Area2D,
_input_event() is called only on the Area2Ds under your cursor.

for a detailed explanation and solution (that I’m using too)

jeyzu | 2019-03-21 15:52