godot
godot copied to clipboard
Awaiting AcceptDialog.visibility_changed causes error but works fine
Tested versions
- Reproducible in: v4.4.rc1.official [8ed125b42], v4.3.stable.official [77dcf97d8]
System information
Windows 11 - OpenGL 3 (Compatibility)
Issue description
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:
- User interacts with
Window Windowemits eitherconfirmedorcanceledsignal.Windowis hidden (either here or before step 2).- Custom signal is emitted. Window is, at this point, hidden.
- 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
- Download MRP. It contains four different functions that do the above using both a
custom signalandvisibility_changed. - Run the function you wish to test in
_ready()