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.

in Engine by (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

+4 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
by (468 points)
selected by

Thank you! It works!

For anyone use Godot 3.5, the suffix not change to ".converted.res"
And you can use this code to know right suffix on game start
```

func _ready():
    if OS.has_feature("standalone"):
    if ProjectSettings.get_setting("editor/convert_text_resources_to_binary_on_export"):
        suffix_tscn = ".converted.res"

```

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 Frequently asked questions and 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 [email protected] with your username.