So, I want to have an inventory that pauses the game whenever it's open, so kinda like Silent Hill. The issue with this is that the time stop is irregular: when the inventory is not open, if you press the inventory key (TAB), the time will stop immediately, and then various animations will play. But when the inventory is open, if you press the inventory key again, the inventory should close, but the time should return to normal after 0.5 seconds. I tried using a boolean to control the time stop, but it didn't work.
If it was just a screen that appeared instantly when pressing TAB, I would just do something like:

if input.is_action_just_pressed(“Inventory”):
      get_tree().paused = not get_tree().paused

But since it has all the delays and animations in between, I can't figure out how to toggle the inventory.

These are the functions I want to execute when pressing the inventory key

func InventoryOn():
	get_tree().paused = true
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
	FadeAnim.play("FadeOut")
	yield(get_tree().create_timer(0.5), "timeout")
	#PLay inventory fade in
	yield(get_tree().create_timer(0.5), "timeout")
	InventoryActive = true
func InventoryOff():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	#Play inventory fade out
	yield(get_tree().create_timer(0.5), "timeout")
	FadeAnim.play("FadeIn")
	InventoryActive = false
	get_tree().paused = false
  • RichNaoo replied to this.
  • Okay I figured out what the issue was
    Since I had all the booleans stored in the player's script, whenever the game paused, the booleans would not update because they were inside the player, which is affected by the time stop. The time stop didn't let the variables update, so that's why the inventory didn't close, because the InventoryActive boolean was not set to true. I'm going to fix this by putting the booleans and all the functions in a node that is not affected by time stop, like the inventory canvas layer itself.
    Thank you all for the comments anyway

    Darxkl05 I suggest using a seperate CanvasLayer for the UI, and set the pause_mode of all the scenes on the UI canvas to Node.PAUSE_MODE_PROCESS. That way you can pause the tree and have the UI still working and checking the inputs.

    It makes sense to be checking for the "inventory" action inside of the inventory scene so you can manage everything related to the inventory from within it. The SceneTreeTimer created by the create_timer() method keeps processing by default when pausing the tree.

    I'm already using a separate CanvasLayer for the inventory, but the issue comes with the fact that I don't know how to apply the 0.5 seconds delay only when the inventory is open and other functions.
    The thing I want to do is execute all the inventory functions and delays in a code that toggles the inventory:
    if input.is_action_just_pressed(“Inventory”):
    get_tree().paused = not get_tree().paused

    Is there a way to execute, for example, InventoryOn() only when the inventory is not opened and the “inventory” key is pressed using the code above? Do I need to create other booleans or use another code in order to specify which actions I want to execute depending on the state of the inventory (opened or not)?

    Yeah, I just use a bool like inventory_open. So:

    if input.is_action_just_pressed(“Inventory”) and not inventory_open:
         InventoryOn()
    elif input.is_action_just_pressed(“Inventory”) and inventory_open:
        InventoryOff()

    I've already tried, but only the InventoryOn() function works, so I can't exit the inventory once I open it. The inventoryOn() functions works perfectly, as well as the time stop, but once I'm in the inventory I can't exit. The boolean doesn't change to true when InventoryOn() finishes, so I guess that's causing the issue. I'm currently doing all of this inside func _physics_process(delta)
    Here's a video of what's currently happening:

    As you can see, the game pauses when the inventory (for now, a black screen) opens, but when I'm inside the inventory, I can't exit. Why is the boolean not being set to true even though it's explicitly written in the function? I'm handling all of this inside the player's script.

    Okay I figured out what the issue was
    Since I had all the booleans stored in the player's script, whenever the game paused, the booleans would not update because they were inside the player, which is affected by the time stop. The time stop didn't let the variables update, so that's why the inventory didn't close, because the InventoryActive boolean was not set to true. I'm going to fix this by putting the booleans and all the functions in a node that is not affected by time stop, like the inventory canvas layer itself.
    Thank you all for the comments anyway