I have problem ,Godot is duplicating my Script file and naming it “script” with out a capital s every time I open the project and having this error in my scripts “class “class_name” hides a global script class.” ,So if anyone has a solution please help.
I had a similar issue. I fixed it by closing all scenes and all script windows. Then I reloaded the project (Project → Reload Current Project). This fixes the problem for me, however, it can reappear, depending on how you attached the script.
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’. 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. It seems to store two references to the same file.
To fix for good, 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.
This isn’t the first time I report something similar and it is quite annoying.
I had one last directory to rename and it’s the “scripts” one, which used non-capital letter and I wanted to fix that. I had given up back then as I was on a roll and didn’t want to go on a tangent.
So, on Windows, I manually renamed the directory. Then using Notepad++ I replaced the “res://scripts/” with “res://Scripts” everywhere it was found and finally renamed the “.godot” directory because it seems to keep references to the former and I thought if it redid its settings and caches it would be fine, but nooooooooooo.
When I try to run the game the engine whines “Class “Room” hides a global script class.” then proceeds to open a copy of “room.gd” which doesn’t really exist anywhere.
It is very likely that I might run Godot to work on a Linux machine and this is unacceptable.
How the engine infers that it needs to open “scripts” instead of the properly saved path “Scripts” in the scene is weird and nonsensical. I haven’t downloaded the engine sources, but I feel I might have to do so since no one appears to check this out.
If anyone wants to add / suggest / correct me, please do so.
This happens when you add a script as a child node (Command+A on Mac, “Plus/Cross Icon” under Scene) instead of instantiating a scene (Shift+Command+A on Mac, “Chain Icon” under Scene).
It produces two scripts instead of the intended singular one, both claiming to be the same class with “class_name”.
Go node by node try to locate which node read from what script and detach the new incorrect script, then attach the the correct, original script. Likely the add child mentioned holds the “fake script”.
Running into the same issue. The script has some weird suffix that I do not know what it means. Nothing I tried worked (reloading, reattaching, renaming files…).
I’m on Windows if it helps debug.
Eventually I removed class_name and all the typing in my script and it worked flawlessly.
I was transitioning from Godot 3.5 to 4.2 to take advantage of the better typing but bugs like this give me pause and maybe I’ll just have to go back to 3.5.
From the screenshot, you have 2 of the same script. One is what is called a built-in script which is saved into the scene and the other is the external script saved to a file.
The suffix is the id of the script embedded in the scene enemy_controller.tscn.
First, get the add-on “Script-IDE” and install it.
Now, when you look at a script file you get tabs which relate to the edit window (a huge benefit) but you also get the missing File, Edit, Search, Go to and Debug menu items.
use the Search tool with “Find in files” to see if your class_name is already used in another class. I found a new_script.gd which should have been deleted which had the same class_name.
This might be related to the case-insensitivity of Windows file paths. I once developed the same project on both Windows and macOS and used Git to manage the code. I found that there were always a few files in Windows whose hash values would change every time I opened the editor, and the changes were clearly visible on Git. After troubleshooting, I discovered that there were case-sensitivity issues with the names of three files. Eventually, I fixed the problem by modifying the file names. Since it was a while ago, I forgot whether I modified and synchronized the file names on macOS or Windows. I suggest you try both.
-------Translation from Doubao.