Hello everyone. Is there any way I can disable input for a collection of nodes on and off? I know I can use a bool to return from processing input, but is there an easier way of doing this that doesn't require editing each script?
Martins You can use Node::set_process_input() to enable/disable input processing for a node. If you want to do it for all the descendants as well, you can write a simple recursive helper. Something like this:
func enable_input(node, enable):
node.set_process_input(enable)
for n in node.get_children():
enable_input(n, enable)
Pulsimeter Thanks! That seems to mostly work, but it sadly doesn't stop input in the _process and _physics_process functions. Is there no way to easily disable a node's ability to listen for input for all functions?
It might be cleaner for you if you utilize viewports for doing what you're trying to do https://docs.godotengine.org/en/stable/tutorials/rendering/viewports.html#input
With xyz's approach, where you are handling the input you can check if is_processing_input():
in order to make sure you should be. All set_process_input(false)
does is prevent _input(event)
from running. It does nothing to _process
, nor even _unhandled_input
nor _gui_input
. See here: https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-set-process-input
You should also be sure that what you're after isn't actually pausing a collection of nodes. Godot has a whole system for handling that.
Martins That seems to mostly work, but it sadly doesn't stop input in the _process and _physics_process functions. Is there no way to easily disable a node's ability to listen for input for all functions?
_process()
doesn't listen to input. Your code explicitly queries global input state in that function via Input
singleton. And this singleton cannot be disabled on per node basis because it doesn't know or care about nodes. So if you don't want to query it from some node... well, just don't do it. You're responsible. Set up your own flag, toggle it recursively as shown above and test it every time you want to access the Input
singleton.
Btw, what do you need this for?
Pulsimeter Btw, what do you need this for?
I'm working on a really ridiculous project called GodotOS where I have an OS-like interface: https://popcar.bearblog.dev/creating-godotos-part-1/
I was just looking for an easy way to disable input for quality of life, when I have multiple game windows open I'd like it for only the active window to receive inputs, but it's not very important really.
Martins Well for this type of thing you shouldn't even need to use Input
. All events can be captured through _input()
handler.
© 2022 - 2024 — McMap. All rights reserved.