0 votes

I am trying to load a scene in the background while displaying a loading screen till the scene loads and then changing the scene to the loaded scene and I am using threads and ResourceLoader to do so. On my computer it runs sometimes and doesn't run other times. And, on android it never gets completed the loading screen comes up and then the game just hangs.

On pressing the play button:

func _on_play_pressed():
        $loading_screen.show()
        go_to_scene(level_to_load, true)

The gotoscene():

func go_to_scene(new_scene, loading):
    if (loading):
        loading_thread = Thread.new()
        loading_thread.start(self, 'prep_scene', ResourceLoader.load_interactive(new_scene), 2)

The prep_scene():

func prep_scene(interactive_ldr):
    while (true):
        var err = interactive_ldr.poll();
        if(err == ERR_FILE_EOF):
            call_deferred("_on_load_level_done");
            return interactive_ldr.get_resource();

The onloadleveldone():

func _on_load_level_done():
    var interactive_ldr = loading_thread.wait_to_finish()
    print('thread', loading_thread.is_active())
    if get_tree().change_scene_to(interactive_ldr) != OK:
        print('error')
in Engine by (31 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.