Hi
One can check for input in all the 3 functions, and even in _process and _physics_process. I'd like an explanation on when to use any of them, and why. I'm looking for best practices.
Thanks.
Hi
One can check for input in all the 3 functions, and even in _process and _physics_process. I'd like an explanation on when to use any of them, and why. I'm looking for best practices.
Thanks.
hello?!
while-free- It's well described in the documentation
https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-private-method-unhandled-input
xyz I've of course read that article. It is not "well" described. Here is an example of vague explanation:
"For gameplay input, this (_unhandled_key_input) and _unhandled_input are usually a better fit than _input, as GUI events should be handled first. This method also performs better than _unhandled_input, since unrelated events such as InputEventMouseMotion are automatically filtered. For shortcuts, consider using _shortcut_input instead."
OK... usually a better fit? When is it NOT a better fit and why?
I need an explanation of "best practices".
I used to use _input for everything. But I found that when I do that for gameplay input, and there are GUI controls such as buttons overlaying the game area, then I need to check whether a mouse click is inside a button so that it can be ignored. By using _unhandled_input for gameplay input, GUI control input is ignored, so there's no need check whether the input is in a GUI control.
By GUI control input, I'm referring to input in nodes that inherit from Control. By gameplay input, I'm referring to input in nodes that inherit from Node2D or Node3D.
while-free- I need an explanation of "best practices".
Start with always using _input()
. When/if you encounter a situation in which events need to be consumed (typically with gui), then look into how _unhandled_input()
works. If those two handlers begin to prove themselves inadequate in your actual project (unlikely), then start looking into other alternative handlers.
xyz So it's kinda a practical thing and depends on the situation. Thanks. This is what I was looking for.