Is this a bug? Resources and precise syntax

I just had an issue with my exported version and after much searching I tracked it down to to typo. Totally my fault, I admit, but it is a bit odd.

When loading a resource the Godot Editor worked fine even though I had a typo in my resource path. I didn’t get an error message and it worked flawlessly

var MyScene = preload(“res://Scenes/ThisScene.tscn”)

and

var MyScene = preload(“res://Scenes/thisScene.tscn”)

Both worked fine running from the editor but only the correct one worked in the exported version. Note the difference is the capital T in thisScene/ThisScene

Should there be an error message for this when the wrong one is used in the editor?

This is a problem when running in Windows and exporting to Windows and Mac. Capital letters in folder and filenames can cause this problem. That’s why the GDScript Style Guide recommends snake_case for file names.

I would recommend changing your code to:

var my_scene = preload(“res://scenes/this_scene.tscn”)

PascalCase is reserved for class names. Variable names should be snake_case. You don’t have to do that, but it will help when debugging, and when you post questions here.

Oh, and it’s not a Godot bug. It’s a Windows bug.

2 Likes

Agreed. File paths are definitely one of those instances where a capital letter is treated differently across platforms.

Thanks. Makes sense. I think it would be good to have a soft warning. It warns me that I have declared a variable and not used it so it would be nice to at least mention that my code won’t run on some platforms, especially Windows. I will be more careful in future though

There is a warning for it, but I think it only appears for files, not text in a script.

1 Like

Create a feature proposal in the project.

Turns out there was a bug. In 3.5 this problem showed as an error when running in the editor, but that error code is missing from 4.5. I am in no qualified to fix it but I have posted it on the Github

1 Like

Share a link here so that any interested people can follow up on it in the future.

1 Like
2 Likes