The Issue
so i noticed a lil bit ago my project automatically updated to Godot 4, without me actually touching it. and ever since that, it didn't even update my code, so there were numerous errors. and while i've managed to fix most of them, i'm having a problem with my ResourceLoader-based scene changing script.
The Code
extends Node
@export var maxLoadTime = 15000
func gotoScene(nextPath, currentScene):
var loader = ResourceLoader.load_threaded_request(nextPath)
var loadIcon = load("res://Scenes/Menus/LoadingIcon.tscn").instance()
get_tree().get_root().call_deferred("add_child", loadIcon)
var curLoadTime = Time.get_ticks_msec()
if loader == null:
print("Resource Loader failed to load resource @ " + nextPath)
return
while Time.get_ticks_msec() - curLoadTime < maxLoadTime:
var prog = loader.poll()
if prog == ERR_FILE_EOF:
var scene = loader.load_threaded_get()
get_tree().get_root().call_deferred("add_child", scene.instance())
loadIcon.queue_free()
currentScene.queue_free()
break
elif prog == OK:
var loadProg = float(loader.get_stage()) / loader.get_stage_count()
loadIcon.value = loadProg * 100
else:
print("There was an unexpected error loading file @ " + nextPath)
await(get_tree().process_frame)
Lines with Errors
the particular lines that show errors are:
var prog = loader.poll()
(Above gives "Cannot call function on enum value")
var scene = loader.load_threaded_get()
and:
var loadProg = float(loader.get_stage()) / loader.get_stage_count()
i've looked everywhere and cannot even find a solution to the first issue. and i'm talking godot documentation, this very q&a forum or even reddit (it was my last try).
If anyone could help in any way, i would really appreciate it as fixing this code is crucial for me to get the project back to full functionality again :)