Topic was automatically imported from the old Question2Answer platform.
Asked By
Conducto
Old Version
Published before Godot 3 was released.
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.
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
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
Thank you! It works!
Conducto | 2017-10-18 08:09
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"