0 votes

After I export my game to Windows the check for a existing scene file always returns false:

var load_path = "res://level" + str(level_to_load) + ".tscn"

if Directory.new().file_exists(load_path):
    print("Loading level " + str(level_to_load))
    get_tree().change_scene(load_path)
    GlobalPlayerData._start_level_time()
else:
    print("Could not find scene file at " + load_path)
    print("Returning to splash screen.")
    get_tree().change_scene("res://SplashScreen.tscn")

If I run the same code from inside the editor the scene file for the level will be found.

asked Oct 17, 2017 in Engine by Conducto (30 points)

As much as i worked with files when you export you cannot change anything in the res:// folder, if you want to be able to change things you need to use the user:// path

1 Answer

+3 votes
Best answer

When you export the game, there is an option Convert text scenes to binary on export. If it's turned on, .tscn files are changed to .tscn.converted.scn.

It seems most paths in scenes/scripts/resources are substituted, but if you have a bit of code that builds the path from parts, it can slip through the cracks.

This is how i handled it in my project.

const SCENETYPE = ['tscn.converted.scn', 'scn', 'tscn']
func load_scene_instance(name, dir=''):
    var file = File.new()
    var path = ''
    var scene = null

    for ext in SCENETYPE:
        path = 'res://%s%s.%s' % [dir, name, ext]
        if file.file_exists(path):
            scene = load(path).instance()
            break

    return scene
answered Oct 18, 2017 by aozasori (460 points)
selected Oct 18, 2017 by Conducto

Thank you! It works!

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.