0 votes
extends Area2D

func _ready():
    $Panel.hide()
    pause_mode = Node.PAUSE_MODE_PROCESS

func on_interact(player):   
    if not $Panel.visible:
        $Panel.show()
        get_tree().paused = true

func _input(event):
    if Input.is_action_just_pressed("interact") and $Panel.visible:
        $Panel.hide()
        get_tree().paused = false

This is the script for an object the player can interact with, which shows a panel with a TextureRect. (They're examining a poster on the wall.) I want the game to pause while the interaction is happening, and then unpause when the player presses Interact again. But right now, it's all happening in a single frame, so in-game it looks like nothing happens at all.

I think the best option might be a timer that triggers a boolean, but I figured I'd see if anyone had a better idea.

Godot version 3.3.1
in Engine by (12 points)

2 Answers

0 votes

You can disable and enable the _input function with set_process_input. Or you can put it in the _unhandled_input function instead of using the _input function (just make to sure to consume the interaction input beforehand).

by (7,452 points)

Hm, I haven't been exposed to _unhandled_input till now. It looks handy and your solution makes sense in theory, but I'm having a hard time getting it to work. What do you mean by "consuming" the interaction input beforehand?

0 votes

Why cant you do it this way:

func _input(event):
    if Input.is_action_just_pressed("interact"):
        if $Panel.visible:
            $Panel.hide()
            get_tree().paused = false
        else:
            $Panel.show()
            get_tree().paused = true
by (722 points)

Well, the initial Interact action comes from Player.gd, and it's also based on a collision with the Player's Raycast2D, to ensure that the player is facing the object they're interacting with.

Though I suppose I could have the Raycast2D simply activate the interactable object it's colliding with, and then put your Input code on the object itself.

I ended up going with the timer + boolean idea. It seemed jankier at first, but upon implementation, I actually like the more weighty feel it gives the interaction.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.