- Find, download, and install the "Godot Async Loader" plugin in AssetLib
- Enable the plugin (Project -> Project Settings -> Plugins -> Enable)
- Add scenes to groups
- Setup plugin in main scene
const GROUPS := [
"terrain",
"building",
"furniture",
"plant",
"item",
"npc",
"etc",
]
func _init() -> void:
SceneAdder._sleep_msec = 100
SceneAdder.set_groups(GROUPS)
- Use the plugin to change to a new scene and load it asynchronously
func _on_start_pressed() -> void:
SceneSwitcher.change_scene("res://examples/World/World.tscn")
# Instance scene asynchronously and add to current scene
var target = get_tree().get_current_scene()
var scene_file := "res://examples/Animals/Puma.tscn"
var pos := Vector3(0, 1, 0)
SceneLoader.load_scene_async(target, scene_file, pos, true)
# 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)
SceneLoader.load_scene_async_with_cb(target, scene_file, pos, true, 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)
# Instance scene synchronously and add to target scene
var scene_file := "res://examples/Animals/Puma.tscn"
var target = get_tree().get_current_scene()
var instance := SceneLoader.load_scene_sync(target, scene_file)