0 votes

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_inputalways 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.

in Engine by (26 points)

1 Answer

0 votes

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.

by (648 points)

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

see https://godotengine.org/qa/28305/collisionobject2d-_input_event-trigger-topmost-collision?show=28305#q28305
for a detailed explanation and solution (that I'm using too)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.