Dialogmethod "popup" only works once

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

Hi,

i have a FileDialog. After a file is selected, i check if the file is good, if not i want to open the FileDialog again with popup_centered. But it is not showing up. If i inspect it in the Editor while running it, i can see that it is not visible.

EDIT:

Some more info…:

var Dialog : FileDialog = FileDialog.new()


func _ready() -> void:
    make_load_dialog()


func make_load_dialog() -> void:
	add_child(Dialog)
	Dialog.access = FileDialog.ACCESS_FILESYSTEM
	Dialog.mode = FileDialog.MODE_OPEN_FILE
	Dialog.resizable = true
	Dialog.popup_exclusive = true
	Dialog.connect("file_selected", self, "path_selected")
	Dialog.get_cancel().connect("pressed", get_tree(), "quit")
	Dialog.get_close_button().connect("pressed", get_tree(), "quit")


[...]
    print("popup") # to see when it should pop up
    Dialog.call_deferred("popup")
[...]
:bust_in_silhouette: Reply From: Zylann

I suppose it’s not working because Godot closes the popup after having fired the file_selected signal. So calling popup_centered from within the function handling that signal won’t have any effect.
Perhaps you could use call_deferred("popup_centered") instead?

Sounds very logical, but does unfortunatly not work.

whiteshampoo | 2020-09-17 06:02

Well, that works for me. I reproduced your issue without call_deferred, and adding it fixed it: it gets closed but because it reopens right away it looks like it remains open. Maybe your code sample is missing a detail?

extends Node

var Dialog : FileDialog = FileDialog.new()


func _ready() -> void:
	make_load_dialog()


func make_load_dialog() -> void:
	add_child(Dialog)
	Dialog.access = FileDialog.ACCESS_FILESYSTEM
	Dialog.mode = FileDialog.MODE_OPEN_FILE
	Dialog.resizable = true
	Dialog.popup_exclusive = true
	Dialog.connect("file_selected", self, "path_selected")
	Dialog.get_cancel().connect("pressed", get_tree(), "quit")
	Dialog.get_close_button().connect("pressed", get_tree(), "quit")
	Dialog.popup()


func path_selected(path: String):
	print("popup") # to see when it should pop up
	Dialog.call_deferred("popup")

Zylann | 2020-09-17 17:21

Ok, on a normal node it works as intended.
I have the FileDialog in a script, that is autoloaded.
Can you please try, if you can get in working on an autoloaded script?

whiteshampoo | 2020-09-24 05:24

Tried on an autoload (which is just another node in the tree), using the same script, works perfectly the same.

Zylann | 2020-09-24 12:54