get_tree().set_paused(true) delays input processing but does not ignore it ?!

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

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 …

small part of game screen

When I click the pause btn (yellow), and I then click a creature (red), nothing happens. Which is what I expected.
But if I then unpause the game, it seems that the click on the creature actually registered (and processing is only postponed, not ignored). The creature disappears from the scene if it was one of the creatures that had to be found.
I assume this is a Godot bug … but does anyone have any suggestions on how I can work around this issue for now ?

Some info :

  • GameRoot : has child Scene (creatures)
  • Scene : has child Bar (buttons)

The pause btn is 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)

The creatures are 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):
		emit_signal("clicked", creature_p)
:bust_in_silhouette: Reply From: icounter

I have the same issue … did you solved it somehow ?

Yes … But it’s more of a workaround than an real solution.

‘Pause’ only seems to work correctly with Controls. So :

  • if you have only a few clickable objects, you can replace the( Area2D + Sprite + CollisionPolygon2D) with a TextureButton.
    However, TextureButtons only work with rectangular clickable regions. So, if you have an irregular shape, you need to also use a ClickMask (Inspector > TextureButton > Textures : Normal (= Sprite shape) + ClickMask (= same shape as CollisionPolygon2D)). The ClickMask is a black and white bitmap (no alpha). You need to re-import it (select bitmap in //res window > import > import as bitmap). If you don’t do this, it won’t work !
    You can now use the click/mouse over events from the button. ‘Pause’ will work correctly.

  • if you have a lot of clickable objects, it’s much easier to have the pause button activate a Control that covers the entire game screen (in the scene tree, it must be below your clickable objects =) ). I used a ColorRect 1920x1080px, with alpha set to 0, and mouse filter set to ‘ignore’.
    When I pause the game, I only need to set the mouse filter to ‘stop’. Unpause : mouse filter = ‘ignore’.

HTH =)

siska | 2019-07-29 07:07

Thanks for your detailed answer. I also found an workaround similar to one of yours, because i really wanted to solve that issue then.
I used a MarginContainer with layout fullrect and set Mouse filter to Stop. This MarginContainer i use it as the container for my pause menu. Also set the pause mode to process for this container and everything works fine.

icounter | 2019-07-29 07:15