Why do tutorials use _unhandled_input(event) instead of _input(event)

Godot Version

Godot 4.3

Question

I followed some tutorials on 3D character movement and camera control (looking around with the mouse), and they detect mouse input with _unhandled_input(event). Why? Is there a good reason to do this over _input(event) or is it the same thing?

_input is handled third in line (after viewport embedded and focused windows), while _unhandled_input is called 7th in line and only if nothing else consumes them. Unhandled Input won’t receive the event if, for example, a UI element took the input first.

Check it out the docs here, once I took some time to understand the order events get handled I was able to solve a lot of my input woes:
https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html

5 Likes

The only thing I would add to @ebrison1 response is an example.

Unhandle input is recommended to be used on player characters so that if a menu is open. The menu can use regular input and set events as handled. This will allow the menu to get the input before the player and prevent player from doing actions while the menu is up.

5 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.