Basically, I want to disable all inputs for a brief moment, so the player is not able to open menus multiple times.
I have an inventory that plays a fade in animation when opening, and then, when it's fully open, a boolean is set to true. After that, when the inventory is closing, it plays a fade out animation and the boolean is set to false.
The issue is that if the player presses the inventory key while the inventory fade in animation is playing, the game plays the animation again, so I want to stop all input while those things happen.

I tried using get_tree().get_root().set_disable_input(true), but it doesn't seem to work. It changes to true and false correctly, but it doesn't seem to affect the input in any way

  • For anyone still having the same issue as me:
    Instead of modifying the inputs, I created a boolean called InventoryEnabled, which by default is set to true. If is set to true, the player will be able to open the inventory, and when it's false, the player won't be able to open it. I did this by only allowing the input inside an if statement that checks if the variable is true:
    func _physics_process(delta):

    if InventoryEnabled == true:
    	if Input.is_action_just_pressed("inventory") and InventoryActive == false and get_tree().paused == false:
    		InventoryOn() 
    		InventoryActive = true
    	elif Input.is_action_just_pressed("inventory") and InventoryActive == true and get_tree().paused == true:
    		InventoryOff()
                       InventoryActive = false

    To prevent the player from opening the inventory while the fade animations are playing I just set the variable to false during the animations

It's best to use boolean flags for this. I usually create a Timer called "Blocker" and then set my flag, set the Blocker to the time of the animation, and when the timer is done it renables control.

    I guess the way cybereality did it is right and nice. But I in a similar situation just introduced a transparent lock screen, which turns on after pressing the key and blocks access to the interface until the animation is over.

    Yeah, that works too. You can use a ColorRect with a zero opacity and set Mouse Capture to Stop.

    cybereality I'm not too familiar with the concept of boolean flags, are they like normal boolean variables? In any case, I already have a timer that tells when to pause the input or not, the thing I don't know is how to disable input for the entire project through code. I think I should also clarify that I would also like to stop keyboard input, so the color rect doesn't solve my issue entirely

      var can_open = true
      
      func _process(delta):
          if can_open == true:
              do_whatever_with_inputs()

      Darxkl05
      This discussion can answer your question:
      https://github.com/godotengine/godot/issues/12581

      The Input singleton has no notion of viewports, it just reports input state as reported by the OS.
      Disabling input for a viewport will simply not propagate InputEvents to it and its children per callbacks.

      maybe you can try this

      var can_open = true
      
      func _process(delta):
          if can_open:
              do_whatever_with_inputs()
         else:
              SceneTree.set_input_as_handled()
      
      func open_dialog():
          set_disable_input(true)
      
      func set_disable_input(disable):
         get_tree().get_root().set_disable_input(disable)       
         can_open = not disable
      
      func time_out():
          set_disable_input(false)

      I'm not sure if it's better to use can_open or get_tree().get_root().gui_disable_input

      This document should give you more ideas
      https://docs.godotengine.org/en/stable/tutorials/inputs/inputevent.html

      I tried doing something like that, but that only stops the mouse input, the keyboard inputs are still active and working perfectly. It seems get_tree().get_root().set_disable_input(true) only disables mouse.

      Is there any other way to do it? Even if it's by disabling only one keyboard input?
      By that I mean that, if stopping all the inputs is not possible, is there a way to disable a specific input? In my case, this Input would be Tab, which corresponds to the inventory key

      11 days later

      For anyone still having the same issue as me:
      Instead of modifying the inputs, I created a boolean called InventoryEnabled, which by default is set to true. If is set to true, the player will be able to open the inventory, and when it's false, the player won't be able to open it. I did this by only allowing the input inside an if statement that checks if the variable is true:
      func _physics_process(delta):

      if InventoryEnabled == true:
      	if Input.is_action_just_pressed("inventory") and InventoryActive == false and get_tree().paused == false:
      		InventoryOn() 
      		InventoryActive = true
      	elif Input.is_action_just_pressed("inventory") and InventoryActive == true and get_tree().paused == true:
      		InventoryOff()
                         InventoryActive = false

      To prevent the player from opening the inventory while the fade animations are playing I just set the variable to false during the animations