Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

Godot Advanced Background Loader

An asset by Master - Main Channel
The page banner background of a mountain and forest
Godot Advanced Background Loader hero image

Quick Information

0 ratings
Godot Advanced Background Loader icon image
Master - Main Channel
Godot Advanced Background Loader

This script allows you to load entire levels and all required assets while playing cutscenes. The attached demo shows a movie, after a while (specifically after reloading assets into temporary memory) a button appears. Clicking it will take the player to the test scene. It does not work on the network because threads are not supported there, and may stutter when loading more complex scenes, or just switching to another scene, e.g. when it was created using the HeightmapTerrain plugin from Zylann.Now this includes the C# version from nonunknown

Supported Engine Version
3.2
Version String
2.0
License Version
MIT
Support Level
community
Modified Date
4 years ago
Git URL
Issue URL

Using CSharp Version of Advanced Background Loader

First Steps

  • Open Godot
  • Open Project Settings
  • Go to Autoload
  • Select BackgroundLoader.cs at res://addons/advanced_background_loader_csharp

Understanding it

since the code provides:

  • public static BackgrounLoader instance ....

when you open the first scene of your game this instance can be accessed anywhere without any problem, from any script just type:

  • BackgroundLoader.instance.MethodNameHere

Basically Background Loader will create a new thread, and load your scene while you still can do other things, (also loads faster due to threading)

Code Examples

  • Simplest case possible
    //set the scene to load and start thread
    BackgroundLoader.instance.PreloadScene("res://scn_menu.tscn"); 
    while(BackgroundLoader.instance.canChange == false) {
            //wait every second to continue, await requires method to have async
            await ToSignal(GetTree().CreateTimer(1,false),"timeout"); 
            //alternatively you can use await ToSignal(GetTree(),"idle_frame")
            //in case you need to load as fast as possible (huge scenes)
        }
    BackgroundLoader.instance.ChangeSceneToPreloaded();
  • Advanced Case

Lets suppose you want to make a transition everytime you want to change scene So we have Transition.ChangeScene(string scenePath);

    public async void ChangeScene(string scenePath) {
        GD.Print("Starting transition");
        //Make the node goes to the top of the screen (appear in front)
        CallDeferred("raise"); 
        //play fade in animation
        animationPlayer.Play("FadeIn");
        Visible = true;

        //Start Preloading next scene
        BackgroundLoader.instance.PreloadScene(scenePath);
        
        while(BackgroundLoader.instance.canChange == false) {
            await ToSignal(GetTree().CreateTimer(1,false),"timeout");
        }

        BackgroundLoader.instance.ChangeSceneToPreloaded();
        //using this code bellow to avoid bugs on the tree
        await ToSignal(GetTree(),"idle_frame");
        CallDeferred("raise");
        animationPlayer.Play("FadeOut");
        GD.Print("Done");

This script allows you to load entire levels and all required assets while playing cutscenes. The attached demo shows a movie, after a while (specifically after reloading assets into temporary memory) a button appears. Clicking it will take the player to the test scene. It does not work on the network because threads are not supported there, and may stutter when loading more complex scenes, or just switching to another scene, e.g. when it was created using the HeightmapTerrain plugin from Zylann.


Now this includes the C# version from nonunknown

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Godot Advanced Background Loader icon image
Master - Main Channel
Godot Advanced Background Loader

This script allows you to load entire levels and all required assets while playing cutscenes. The attached demo shows a movie, after a while (specifically after reloading assets into temporary memory) a button appears. Clicking it will take the player to the test scene. It does not work on the network because threads are not supported there, and may stutter when loading more complex scenes, or just switching to another scene, e.g. when it was created using the HeightmapTerrain plugin from Zylann.Now this includes the C# version from nonunknown

Supported Engine Version
3.2
Version String
2.0
License Version
MIT
Support Level
community
Modified Date
4 years ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers