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
2.17k stars 71 forks source link

Parse Error: Class "PhantomCamera3D" hides a global script class. #275

Closed TranquilMarmot closed 5 months ago

TranquilMarmot commented 5 months ago

Issue description

Godot v4.2.2.stable.mono - macOS 14.1.1 - Vulkan (Forward+) - integrated Apple M1 - Apple M1 (8 Threads) Phantom Camera v0.7.0.4

On startup, Godot logs the following:

 res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_3D.gd:3 - Parse Error: Class "PhantomCamera3D" hides a global script class.
  modules/gdscript/gdscript.cpp:2726 - Failed to load script "res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_3D.gd" with error "Parse error". (User)
  res://addons/phantom_camera/scripts/resources/camera_3D_resource.gd:2 - Parse Error: Class "Camera3DResource" hides a global script class.
  modules/gdscript/gdscript.cpp:2726 - Failed to load script "res://addons/phantom_camera/scripts/resources/camera_3D_resource.gd" with error "Parse error". (User)

Likewise, when running the game it immediately crashes with:

Parser Error: Class "PhantomCamera3D" hides a global script class.

Somehow, this is broken even rolling back the files changed by the auto-update 😢 To get the project running again, I had to delete the local .godot directory, re-load the project, and then reject the phantom camera update.

Steps to reproduce

Upgraded from Phantom Camera v0.6 (I think? I had cloned the repo) to v0.7.0.4 via auto-update

(Optional) Minimal reproduction project

No response

TranquilMarmot commented 5 months ago

An easy fix if you're coming to this issue:

Do a case-sensitive global find-and-replace in all of your .tscn files of:


Okay, I think I tracked this down by...

Looking at the diffs between what was broken and what now works, I do see:

BAD:
- [ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_3D.gd" id="3_mpxdu"]
- [ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/camera_3D_resource.gd" id="6_jcc6h"]

GOOD:
+ [ext_resource type="Script" path="res://addons/phantom_camera/scripts/phantom_camera/phantom_camera_3d.gd" id="5_cnjle"]
+ [ext_resource type="Script" path="res://addons/phantom_camera/scripts/resources/camera_3d_resource.gd" id="7_rjqcs"]

Note the difference between phantom_camera_**3D**.gd and phantom_camera_**3d**.gd

My guess is that the addon first loaded phantom_camera_3d.gd (which is correct!) and then when my scene is loaded, it loads phantom_camera_3D.gd. Godot thinks that this is a different file and tries to override the class_name which causes the exception.

This issue also mentions this; https://github.com/ramokz/phantom-camera/issues/274


Some thoughts...

Could the updater do this ☝️ as part of the update? Or is it just a simple download script that wouldn't be able to?

Should the docs have a migration guide from 0.6 to 0.7 that mentions this?

ramokz commented 5 months ago

Dup of #263 and #272

tldr: this is more of a Godot editor issue than an addon one, where it randomly struggles with file renaming at times. Some report that reopening the project multiple times resolved their issues.