+1 vote

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 in Engine by Diet Estus (1,261 points)
edited May 13 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 by alfandango (73 points)
selected Jul 6 by Diet Estus
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.