Interactive resource loading

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

i am trying to create a loading screen using the interactive resource loader. I am mainly using the code provided by this example : godot-docs

Everything works for me except the updating progress bar. When i start the function my loading screen pops up but the progess bar doesnt move.
I have tried printing the progress each time the loader polls and i found out it only calls the updateProgress() function after it finished loading everything.

this is the process function:

if loader == null:
if wait_frames > 0:
	wait_frames -= 1
var t = OS.get_ticks_msec()

while OS.get_ticks_msec() < t + time_max:
	var err = loader.poll()
	if err == ERR_FILE_EOF:
		var resource = loader.get_resource()
		loader = null
		game_instance = resource.instance()
	elif err == OK:
		updateProgress() -> **this function only triggers after everything  is loaded**
		print("error during loading")
		loader = null

does anybody know a solution?

thanks and best regards

:bust_in_silhouette: Reply From: Lopy

It seems like your code is calling updateProgress() many times, but all inside the same tick, with no opportunity for your progress bar to visually update.

You can add gaps in your loop by adding a yield(get_tree(), "idle_frame") as the first instruction of your loop. This will allow other things to be processed in between each iteration.

If you have many small loads, you can use OS.get_ticks_msec() to figure out if you have enough time left in your tick (~=16ms) to not yield yet into the next one.

updateProgress() could also be faulty, but it’s code is not included in the question. You can add a print to it to see when it is called.