godot icon indicating copy to clipboard operation
godot copied to clipboard

Awaiting AcceptDialog.visibility_changed causes error but works fine

Open azuriancomet opened this issue 9 months ago • 0 comments
trafficstars

Tested versions

  • Reproducible in: v4.4.rc1.official [8ed125b42], v4.3.stable.official [77dcf97d8]

System information

Windows 11 - OpenGL 3 (Compatibility)

Issue description

Image

The idea is "user action required before continuing".

AcceptDialog and ConfirmationDialog do not have a signal that you can receive when the user does anything (either confirms, closes, or presses a different button you added). It will, however, hide the window and emit the visibility_changed signal whenever you press anything.

This approach works as intended. The Windows appear in order, and interacting with them does what it's supposed to. It will, however, print an error every time you call show() or popup(), with the exception of the first one.

Workaround

You can attach a script to the Window in question and define your own signal:

extends AcceptDialog

signal user_acted


func _ready() -> void:
	canceled.connect(func() -> void:
		user_acted.emit())
	confirmed.connect(func() -> void:
		user_acted.emit())

This half works, as whenever the canceled signal is triggered (when pressing the button or closing the window), the Window will not be visible on the next loop iteration. This is strange because the confirmed signal works correctly. You can fix this by emitting the custom signal deferred.

I am unsure what the problem is here, as one would imagine the process to be straightforward:

  1. User interacts with Window
  2. Window emits either confirmed or canceled signal.
  3. Window is hidden (either here or before step 2).
  4. Custom signal is emitted. Window is, at this point, hidden.
  5. Loop receives the signal and continues iterating.

Other notes

I have tried, unsuccessfully, different flag combinations and settings for ConfirmationDialog and AcceptDialog, as well as manually hide()ing them. I've also tried using the close_requested signal, but it doesn't emit when pressing the Cancel Button, only when closing the Window. The get_cancel_button().pressed, on the other hand, doesn't emit when closing the Window.

Given that using visibility_changed works as intended but prints errors, and I couldn't find anything about this online or in the docs, I am unsure if this is a bug or I'm doing something wrong.

Steps to reproduce

  1. Download MRP. It contains four different functions that do the above using both a custom signal and visibility_changed.
  2. Run the function you wish to test in _ready()

Minimal reproduction project (MRP)

confirmation-dialog-error-4.4.rc1.zip

azuriancomet avatar Feb 23 '25 17:02 azuriancomet