Skip to content

Instantly share code, notes, and snippets.

@hiulit
Created September 6, 2022 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiulit/b093e5d6373aef2a8a3026db9aff5c9f to your computer and use it in GitHub Desktop.
Save hiulit/b093e5d6373aef2a8a3026db9aff5c9f to your computer and use it in GitHub Desktop.
Enable/disable input for the whole game/app
func disable_input(actions_allowed = []) -> void:
for action in InputMap.get_actions():
# Allow some input actions.
if action in actions_allowed:
continue
# Remove the action and its events.
InputMap.action_erase_events(action)
InputMap.erase_action(action)
# To avoid the error: The InputMap action "xxx" doesn't exist.
InputMap.add_action(action)
func enable_input() -> void:
InputMap.load_from_globals()
@hiulit
Copy link
Author

hiulit commented Sep 6, 2022

Example of allowing some input actions:

disable_input(["ui_accept", "ui_cancel"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment