Signal emitted at resuming after get_tree().paused = true ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By metalganon

Hello everyone,

First, I would like to thank all the godot community members for their tools and clear support material.

However, I have a question about the behavior of the pause feature: why are some signals emitted at resuming?

I made a Minimal Working Example to reproduce the behavior that I am talking about. Here is the scene node tree (sorry my godot is in French):

The pause mode of the main Node is “Process”, the one of the Area2D is “Stop” and the one of the CollisionShape2D is “Inherit”.

The gdscript attached to the Main node is the following:

extends Node2D

func _ready():
    $Area2D.connect("mouse_entered", self, "_on_Area2D_mouse_entered")

func _input(event):
    if event is InputEventKey:
        if event.scancode == KEY_ESCAPE and event.is_pressed():
            get_tree().paused = not get_tree().paused

func _on_Area2D_mouse_entered():
    print("MOUSE_ENTERED")

So:

  • When the mouse enters the CollisionShape2D, an output message “MOUSE_ENTERED” is printed.
  • When the escape button is pressed, the game is paused. In that state, when the mouse enters the CollisionShape2D, nothing is printed.

That’s okay, that’s cool. However, when the mouse enters the CollisionShape2D at least once during the pause, the message “MOUSE_ENTERED” is printed when resuming (hitting escape again), even if the mouse is not in the CollisionShape2D when hitting escape. Personaly, I find that kind of unexpected…

Do you have any idea about how to prevent “MOUSE_ENTERED” to be printed on resuming? I tried to disconnect the signal during the pause but it is not working…

Thank you for your time and attention,

MetalGanon.

My only suggestion would be to disable the Area2D when it’s paused and, when unpausing, enable the Area2D.

rahsut | 2020-08-18 13:12