ramokz / phantom-camera

👻🎥 Control the movement and dynamically tween 2D & 3D cameras. Built for Godot 4. Inspired by Cinemachine.
https://phantom-camera.dev/
MIT License
1.93k stars 62 forks source link

Class "PhantomCamera2D" hides a global script class #263

Closed tayete closed 2 months ago

tayete commented 2 months ago

Issue description

I have just updated to 0.7. No dependency errors, but an error at loading the project: " (4) drivers/windows/file_access_windows.cpp:127 - Case mismatch opening requested file 'phantom_camera_2D.gd', stored as 'phantom_camera_2d.gd' in the filesystem. This file will not open when exported to other case-sensitive platforms. res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2D.gd:3 - Parse Error: Class "PhantomCamera2D" hides a global script class. modules/gdscript/gdscript.cpp:2726 - Failed to load script "res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2D.gd" with error "Parse error". (User) drivers/windows/file_access_windows.cpp:127 - Case mismatch opening requested file 'phantom_camera_2D.gd', stored as 'phantom_camera_2d.gd' in the filesystem. This file will not open when exported to other case-sensitive platforms.

When running the scene, the "Class "PhantomCamera2D" hides a global script class" error appears, from the script phantom_camera_2D.gd I don't see in the guide how this errors fit with the cases provided.

Steps to reproduce

Update Phantom Camera...

(Optional) Minimal reproduction project

No response

ZenithStar commented 2 months ago

Godot is really bad about handling renamed files, and the 0.7 update renamed phantom_camera_2D.gd to phantom_camera_2d.gd (the d became lowercased). I fixed it by deleting my .godot folder and letting it regenerate. Make sure any PhantomCamera2D nodes in any of your scenes points to the lowercase version.

Meliketoaste commented 2 months ago

yeah i noticed. Couldnt you just delete the one with a big d?

Meliketoaste commented 2 months ago

You should be able to rename .godot/editor/script_editor_cache.cfg and rename [res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_2D.gd]

ramokz commented 2 months ago

What @ZenithStar said, it's a common issue with Godot annoyingly. The typical practice is to delete the .godot directory, much like the Library folder in Unity.

Have added a note in the 0.7 release notes to include that for others.

ramokz commented 2 months ago

I don't want to sound rude, but may I ask why were the Ds in 3D and 2D for the 2 script filenames renamed to be lower case? It honestly seems like such an unnecessary change to make. I'd understand if you changed whole words for the filenames, but lowercasing one letter for both of them? I'm going to be sensible and assume that somehow it's for readability.

The tldr is in the release notes, but I can give a longer answer.

Nothing to do with readability, but rather naming convention consistency. When you start working with many files, it begins to become confusing when some are written one way, and others another. The naming convention was a bit all over the place due to how little I knew about Godot when I started the project and due to how much experimentation was happening. As the project evolved, the system began to consolidate. It came to a point where having various styles became an issue when referencing them in code, as you had to deal with cases such as “this one file was written differently from others, so I have to remember to, arbitrarily, uppercase this one letter at the end”. It also makes it easier for contributors to know what to call new files if there's a consistent pattern to follow, rather than it becoming a guessing game.

tayete commented 2 months ago

I am afraid none of the solutions (renaming the cfg and deleting .godot) worked, the "...hides a global script class" error keeps stopping the run. Getting back to 0.6 for a while...

ZenithStar commented 2 months ago

When I upgrade to 0.7, I deleted my addons/phantom_camera directory and copied in the new version, and it also took several deletes of my .godot for Godot to figure things out. Does anyone know if there's another hidden cache somewhere? g1gl3qpmcy1c1

ramokz commented 2 months ago

[...] it also took several deletes of my .godot for Godot to figure things out. Had similar experiences where Godot didn't load certain things until relaunching the project multiple times. So it does seem like there's something that's not being triggered correctly behind the scenes all the time.

Been looking around a bit more, and this particular issue seems to have been discussed in a few other posts.

The original error message about Class "PhantomCamera2D" hides a global script class is only displayed if another classes with the same name is declared somewhere else. So unless one has written it themselves, then the issue would suggest that the class name declaration has been stored somewhere but not updated at that place.

The post here has a few suggestions for what to potentially try.

fwiw, one idea to try is to open the project directory in an IDE, search for instances of phantom_camera_2D, with case matching enabled, and see if there's any hidden files in the project that didn't update the class name or file path.

Personally, I don't recall experiencing the issue that the original post described when I did some test installations a few days ago — neither from a freshly made project nor an existing one with 0.6.4 installed. So the issue seems to appear very inconsistently and is relatively random whether if one encounters it or not. That said, it does feel like it's a single file that just refuses to update a string path.

edit: Another couple of suggestions to try.

tayete commented 2 months ago

I tried all the solutions and none seem to work. But closing and reopening several times the project seemed to work. Now I only need to change small things like "set_follow_target_node" which now is "set_follow_target" and everything seems to be fine. Than you all for the help and specially @ramokz for this extraordinary addon!!!

ramokz commented 2 months ago

You're welcome! Glad you found a solution, and thanks for the patience :)