Is the input function still used in version 3.1 and up?

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

I was using an older tutorial that used the fixed process function, and also a built in function called func _input(event). It also put, set_process_input(true). Is this still applicable to the current version of Godot?

The tutorial mentioned that functions that check for input should be but in this function, instead of the fixed process function (now physics process funtion). Is that still true?

:bust_in_silhouette: Reply From: Zylann

Yes, the function is still used, if you want to catch all input events regardless of anything (even if some UI is shown).
It is now enabled by default if you declare it, so no need to do set_process_input(true), unless you want to turn it off.

Thanks for responding. So, if I check for a lot of input, I should put it in the input function instead of the physics process function? In the tutorial, when the input code was copied from the fixed process function and pasted in the input function, it broke the game, and extra tweaking had to be done to make it work. Will that still need to be done?

Millard | 2019-10-30 16:31

Checking input with the Input singleton and using the _input method are two very different ways of handing input.

The Input singleton checks realtime input states, even though it has some event-like methods. It means no matter what happens in the game or the engine, it will tell you the current input. That also means it doesn’t check anything like pause mode, GUI in front of the player or text fields being in use etc, those cases are up to you to manage manually.

The _input method (and its _unhandled_input and _gui_input counterparts) go the other way around: they gets called only when input changes (or events) actually occur, so it doesn’t run every frame, only when it needs to. Because of that, it is often preferred when GUI interaction comes in, because the engine can decide when your code gets called (i.e if a window blocks the mouse, it will send clicks to the script on that window, and not the game behind it).

All this design didn’t change much in 3.0, check this InputEvent — Godot Engine (3.1) documentation in English

Zylann | 2019-10-30 18:41

Thnx for the info :slight_smile:

Millard | 2019-10-31 02:23