Closed workhorsy closed 2 years ago
A few problems with a basic example:
. Target isn't supplied to the callback, so you need to look it up, or pass it in using the data dict . You might not even be adding the node to anything, so having the target is useless. . Other critical data such as owner is missing . Too many arguments make the call longer, often going over one line in length
# Instance scene asynchronously and send to callback
var target = get_tree().get_current_scene()
var scene_file := "res://examples/Animals/Puma.tscn"
var pos := Vector3(0, 1, 0)
var is_pos_global := false
SceneLoader.load_scene_async_with_cb(target, scene_file, pos, is_pos_global, funcref(self, "on_animal_loaded"), {})
func on_animal_loaded(path : String, instance : Node, pos : Vector3, is_pos_global : bool, data : Dictionary) -> void:
var target = get_tree().get_current_scene()
instance.transform.origin = pos
target.add_child(instance)
A better option for load_scene_async_with_cb:
# Instance scene asynchronously and send to callback
var data := {
"target" : get_tree().get_current_scene(),
"pos" : Vector3(0, 1, 0),
"is_pos_global" : false,
}
var cb = funcref(self, "on_animal_loaded")
var scene_file := "res://examples/Animals/Puma.tscn"
SceneLoader.load_scene_async_with_cb(scene_file, cb, data)
func on_animal_loaded(instance : Node, data : Dictionary) -> void:
var target = data["target"]
target.add_child(instance)
instance.transform.origin = data["pos"]
Fixed in #14
Using SceneLoader.load_scene_async_with_cb is confusing.