Replies: 3 comments 5 replies
-
Out of curiosity, why do you need to temporarily disable an input? If you want to prevent player movement during a certain game state, it's better rely on the current game state or player properties instead. |
Beta Was this translation helpful? Give feedback.
-
See input processing order. If the node that should block input is located correctly, then you can use the methods Contol.accept_event, Viewport.set_input_as_handled or SceneTree.set_input_as_handled to stop the further propagation of the input event. For example: extends Camera2D
var _block_input = false
func _input(event):
if _block_input: # You can also check which actions using is_action.
get_viewport().set_input_as_handled()
func animate():
_block_input = true
# ...Your code here...
_block_input = false If you are absolutely sure that you need to block all input, then there is the Viewport.gui_disable_input property. |
Beta Was this translation helpful? Give feedback.
-
Add this script as an Autoload named extends Node
var disabled_actions := PoolStringArray()
func _input(event: InputEvent) -> void:
for action in disabled_actions:
if event.is_action(action):
get_tree().set_input_as_handled()
return
func disable_action(name: String) -> void:
if not name in disabled_actions:
disabled_actions.append(name)
func enable_action(name: String) -> void:
var idx := disabled_actions.find(name)
if idx != -1:
disabled_actions.remove(idx) |
Beta Was this translation helpful? Give feedback.
-
It would really help me if there was a way to temporarily disable and enable an action trough code, without making clunky bools for many inputs to check in my code manually. Personally, this would make my code cleaner and easier to work with.
I've imagined something like
InputMap.disable_action(action)
andInputMap.enable_action(action)
.Beta Was this translation helpful? Give feedback.
All reactions