• Godot HelpProgramming
  • Possible bug : get_tree().set_paused(true) delays input processing but does not ignore it ?!

I have been working on a hidden object game for a while and I'm now at the point where I wanted to implement game pausing.

Reading the Godot 3.1 docs, I thought it would be fairly simple to do, but I hit a snag ...

When I click the pause btn (yellow), and I then click a creature (red), nothing happens (which is what I expect). But if I then unpause the game, I can see that the click on the creature has actually registered and processing is only postponed, not ignored. I assume this is a Godot bug ... but does anyone have any suggestions on how I can work around this issue for now ?

SceneTree : GameRoot : has child Scene (with creatures ; everything above pink rect) Scene : has child Bar (with buttons ; everything inside pink rect)

Pause btn : A TextureButton with the pause-mode set to 'process' in the editor. Its code :

func _on_pause_btn_up():
    is_paused = !is_paused
    get_tree().set_deferred("paused", is_paused)

Creatures : Created as an Area2D with 2 children : a Sprite and a CollisionPolygon2D. They register clicks like this :

func on_LMB(viewport, event, shape_idx, creature_p:Area2D):
    if(event.is_action_released("LMB")):
        emit_signal("clicked", creature_p)

(This is Godot 3.1.1 on Windows 10.)

Here is what I would try doing to get around the issue:

On the pause/resume button, have it call a function in GameRoot (example set_game_pause) that sets a variable (example game_paused) before calling set_deferred("paused", is_paused).

Then in the creatures script, add a check to see whether game_paused in GameRoot is true. If game_paused is true, then discard/ignore the input event. This way you can control whether input events will be processed independently of the pause itself by changing game_paused.

Finally, once the game is un-paused and set_game_pause is called, have GameRoot wait on a short timer before setting the game_paused variable back to false. This will allow all of the delayed input events to be processed and discarded by the creature scripts.

That is what I would try. This will make a small delay before new inputs can be processed, but that should hopefully work around the issue.

Hopefully this helps :smile:

Ah ! Great idea ! I hadn't thought about having the creatures check a pause variable before responding to click events ... Thanks !

Edit : Sadly couldn't get the above suggestion to work ... I can't figure out how to disgard the input event. :/

4 years later