Getting "hides global script class" error but class only defined once

Godot Version

v4.3.stable.official [77dcf97d8]

Question

I am trying to make a 2D game.

The game was working perfectly fine not long ago. I have an Inventory scene, and a new hotbar scene. I was trying to make the hotbar scene inherit the inventory scene when the issue randomly appeared. I have little clue as to what I did that might’ve triggered it.

The error:
Parser Error: Class "PlayerInventory" hides a global script class.

Troubleshooting Efforts

I conducted a search using PowerShell, and it just shows that it’s being referenced in two other scripts, which should be the case, as that has remained unchanged for most of its development.

I tried renaming the class, but the references immediately stop working.

I then went into the references and reformatted them too, but then I got the same error.

I tried removing the class from the files entirely, and the same thing happened.

I checked my autoloads, and I didn’t note anything weird. I also deleted my .godot folder. Restarted my computer. Nothing.

When I CTRL+LCLICK PlayerInventory, it takes me right to the same “inventory.gd” script that originally spat out the error.

Thoughts

I’m sure the solution is something small and silly but right now, I don’t know what to do and I feel like I’m running out of options. It was working perfectly fine before, so I’m confused.

I found this comment on a similar thread that provided this solution:
Solution to similar thread

But to be honest, I don’t understand what it’s saying for me to do, and the thread was never resolved so I don’t even know if this is the right solution.

If it is, I’d appreciate an explanation as to what’s happening here.

If any more screenshots or information is needed, let me know!

Screenshots



Start by avoiding built-in scripts with class_name, you can select the Script resource and right click “Save As…” to keep it on-disk.

Built-in scripts do not show in your search query since you only look for *.gd files, and you do have another class_name PlayerInventory in your “Scripts/Unattached/inventory.gd” that is global.

1 Like

Oh I see now! Thank you so much!

I wasn’t entirely aware of how Godot handles scripts, so I was unaware of the built-in and non-built-in distinction. I realize now that I do like to keep all my scripts discrete and on-disk.

I was wondering though: Is there a reason Godot does this? I never had the issue before. Is there ever a good time to use built-in scripts?

What I did

Realized the built-in script on my inventory node and my inventory.gd scripts were essentially identical. I wasn’t entirely confident that just detaching the script and closing it would delete it, so I did as you said and saved it as something like toDelete.gd and then did. I attached my inventory.gd script to it and everything works perfectly again!

Thank you!

P.S. Here’s what you helped me fix:

1 Like

Just as a quick aside, I always use the add-on “Script-IDE” with every project. Among the benefits is that it adds a Search menu item with a “Find in Files” option. When I’ve had the “hides global script class” error before I search for the class name using “Find in Files” and I can instantly see where I accidentally defined it twice.

1 Like

Every resource can be built-in, this includes scripts, however scripts have a lot of functionality that is hindered by being built-in but rather than trying to remove scripts as built-in (something core to Resources) Godot is trying to round out those problems.

1 Like

None of the above helped me, but I found the solution and want to help anyone who finds this: Your function name tries to override an existing native Godot function.

In my case, I had a function named duplicate, and that is why it gave me this error!

1 Like