Skip to content

Commit 61d7a5b

Browse files
committed
Import files explicitely instead of waiting for scan.
This was an old workaround, which still worked in Godot 4, until recently I found it could actually break. While testing on a different computer, Resources didn't load after the waited frames, unless I waited for longer. I suspect threaded import made it less reliable. It seems there are nicer APIs now, hopefully it's the right way to go.
1 parent 659da22 commit 61d7a5b

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

addons/zylann.hterrain/tools/texture_editor/set_editor/texture_set_import_editor.gd

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -650,38 +650,16 @@ func _on_ImportButton_pressed():
650650
_show_error("EditorFileSystem is not setup, can't trigger import system.")
651651
return
652652

653-
# ______
654-
# .-" "-.
655-
# / \
656-
# _ | | _
657-
# ( \ |, .-. .-. ,| / )
658-
# > "=._ | )(__/ \__)( | _.=" <
659-
# (_/"=._"=._ |/ /\ \| _.="_.="\_)
660-
# "=._ (_ ^^ _)"_.="
661-
# "=\__|IIIIII|__/="
662-
# _.="| \IIIIII/ |"=._
663-
# _ _.="_.="\ /"=._"=._ _
664-
# ( \_.="_.=" `--------` "=._"=._/ )
665-
# > _.=" "=._ <
666-
# (_/ \_)
667-
#
668-
# TODO What I need here is a way to trigger the import of specific files!
669-
# It exists, but is not exposed, so I have to rely on a VERY fragile and hacky use of scan()...
670-
# I'm not even sure it works tbh. It's terrible.
671-
# See https://github.com/godotengine/godot-proposals/issues/1615
672-
_editor_file_system.scan()
673-
while _editor_file_system.is_scanning():
674-
_logger.debug("Waiting for scan to complete...")
675-
await get_tree().process_frame
676-
if not is_inside_tree():
677-
# oops?
678-
return
679-
_logger.debug("Scanning complete")
680-
# Looks like import takes place AFTER scanning, so let's yield some more...
681-
for fd in len(files_data) * 2:
682-
_logger.debug("Yielding some more")
683-
await get_tree().process_frame
684-
653+
# Notify Godot's file system that new files were created
654+
for fd in files_data:
655+
_editor_file_system.update_file(fd.path)
656+
657+
# Import new files
658+
var files_paths := PackedStringArray()
659+
for fd in files_data:
660+
files_paths.append(fd.path)
661+
_editor_file_system.reimport_files(files_paths)
662+
685663
var failed_resource_paths := []
686664

687665
# Using UndoRedo is mandatory for Godot to consider the resource as modified...

0 commit comments

Comments
 (0)