godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.07k stars 21.14k forks source link

For scripts, Godot treats paths as case-insensitive in attach script window, but case-sensitive when running the project. #91969

Open mightyherc opened 5 months ago

mightyherc commented 5 months ago

Tested versions

System information

Windows 11 - v4.2.2.stable.official [15073afe3]

Issue description

Godot (maybe when running on Windows only) does not use case-sensitive folder names. It will recognize “Scripts” and “scripts” as the same folder, at least when attaching a script.

My issue is that when attaching the scripts to the scene, I used the the lowercase ‘s’ instead of the uppercase ‘S’. This worked OK for some time, but when reopening my project, it stopped working with the error Parse Error: Class "" hides a global script class. . Godot seems to be case-sensitive when defining classes because it it finds the scripts in the “Scripts” folder and the “scripts”, which are the same script. It seems to store two references to the same file.

To workaround, I had to update the script location. I detached the script from the affected scenes and reattached it making sure to select the file from the file browser instead of typing it in.

Expected: Godot consistently recognizes the file paths as case-insensitive or case-sensitive (e.g. attach popup is case-sensitive or the script loader(?) is case-insensitive).

Steps to reproduce

. Create new project . Create new folder for scripts ("Scripts") . Create new scene . Attach new scripts in popup using the path "/scripts" (note use lowercase 's') . Assign a class name to the script and save . Open the created script from the FileSystem area. . Should see two script windows: one for scripts/... and one for Scripts/... . May see popup indicating that one file is out of date. hit reload. . See Parse Error: Class "" hides a global script class.

Minimal reproduction project (MRP)

MRP-script-file-causes-parse-error.zip

dalexeev commented 4 months ago

See Project organization - Case sensitivity.

Calinou commented 4 months ago

. Attach new scripts in popup using the path "/scripts" (note use lowercase 's')

How did you achieve this? Did you manually enter the path in the text field?

mightyherc commented 4 months ago

Yes, I manually typed it in. I was double clicking the default folder (e.g. Scenes) then typing "scripts". Being lazy, I was not capitalizing the 's' since it worked.

mightyherc commented 4 months ago

@dalexeev, thanks. Sorry, I missed the message. The section specifies that issues may occur when exporting projects. I am still learning Godot so maybe I am missing something. However, setting the case-sensitivity in Windows (as per your link) avoids the problem from happening (i.e. Godot does not recognize "scripts" and "Scripts" as the same path).

I still feel this is odd behaviour. I was trying to find a suggestion, but I have no C++ experience and no experience with Godot source code. I reviewed some parts of the source code. My thinking was to have the ScriptCreateDialog::_path_changed set the path equal to whatever the path actually is (e.g. check if the path exists, then read back the path from the OS). So, if a user enters ".../scripts/..." and the folder is ".../Scripts/..." (and, Unix, "scripts" does not exist), the text field would display ".../Scripts/...". The main thing I am not sure about is how can you say "what is the path for this path"...Seems like a weird thing to do and not sure if it is supported. Some googling suggests it is, but as mentioned, I have no real experience.

I noticed there are different classes for Windows and Linux for the directory access, so maybe there could be a function in there to return the path? Unix would just return whatever path was passed in. Function could be called when directory exists.