+2 votes

I have been using a custom input processing function that references the Input singleton:

func input_processing():
    if Input.is_action_pressed("right"):
        ...

I call this function in _physics_process() before my physics code.

I could achieve the same effect using the virtual function _input(event). For example,

func _input(event):
    if event.is_action_pressed("right"):
        ...

Is there an advantage to using _input(event) over the custom function which references the Input singleton?

asked May 13, 2018 in Engine by Diet Estus (1,504 points)
edited May 13, 2018 by Diet Estus

1 Answer

+1 vote
Best answer

Input is an OS specific global singleton object created by the system when the game is loaded. It stores the input_map and (AFAIK) binds the system InputEvent(s) object so that it can track inputs from the system during the game loop. It is independent from any specific Node or Scene.

_input() is a node specific method which is fired only when an input is detected and does something. It can not for example keep track of whether a key or mouse button for example is being held down or (I assume) when it is released.

This is only my understanding so far,I hope it helps.

answered Jul 6, 2018 by alfandango (79 points)
selected Jul 6, 2018 by Diet Estus

It can not for example keep track of whether a key or mouse button for example is being held down or (I assume) when it is released.

I'm not sure this is entirely accurate. event.is_action_pressed(..) has an optional bool for allow_echo, a method event.is_echo(), and there is also a method event.is_action_released(..).

Is there more information on how "Node specific method" vs "OS specific global singleton" which "is independent from any specific Node or Scene" could affect things?

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 How to use this Q&A? before posting your first questions.