What is the difference between _UnhandledInput ,_Input,._ShortcutInput

Godot Version



I view many tutorials are using the _Input method for capturing mouse and keyboarded keys
But when looking at the:
public virtual void _UnhandledInput(InputEvent @event) functions comment
it is recommended to use this as its higher priority .
so what is the difference and when to use what ?

_input() will be called before GUI, _unhandled_input() after. In most cases when using GUI you better go with _unhandled_input().

You can read more here: Using InputEvent — Godot Engine (stable) documentation in English

1 Like

One difference is the order, in which these are called.

Use _input, when you need to access the event, before it is handled by the gui Control nodes. Since in most cases the behavior of gui Control nodes should not be changed, the recommendation is to listen in _unhandled_input() for input events.

Another difference is the type of input events, that each of these input-functions receives.

  • _input() and _unhandled_input() receive all input events
  • _shortcut_input() receives only keyboard events, shortcut events and joypad button events
  • _unhandled_key_input() receives only keyboard events, so when you want to act on keyboard events, then it is more efficient to use this function instead of _unhandled_input()

A third difference is the nodes, that get called with these functions.

  • _gui_input() is called only in Control nodes
  • _input() and _unhandled_input() and other functions are called in nearly all nodes (exception example: Window)

Here is a graphic, that tries to summarize these details:

1 Like