Skip to content

A Godot plugin to load, instance, and add scenes asynchronously using a background thread.

License

Notifications You must be signed in to change notification settings

ImmersiveRPG/GodotAsyncLoader

Repository files navigation

Godot Async Loader

Video on how plugin works

Loading scenes asynchronously in Godot

How to install and use plugin

  1. Find, download, and install the "Godot Async Loader" plugin in AssetLib

groups

  1. Enable the plugin (Project -> Project Settings -> Plugins -> Enable)

groups

  1. Add scenes to groups

groups

  1. 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)
  1. 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")

How to load child scene async

# 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)

How to load child scene async with callback

# 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)

How to load child scene sync

# 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)

About

A Godot plugin to load, instance, and add scenes asynchronously using a background thread.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published