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

Identifier "PhantomCamera2D" not declared in the current scope #298

Closed HeavensSword closed 2 months ago

HeavensSword commented 4 months ago

Issue description

I'm getting the error "Parse Error: Identifier "PhantomCamera2D" not declared in the current scope." intermittently when hitting play from the Godot editor. This has been happening more frequently it seems like, especially after updating to the latest version. Sometimes it runs, other times it fails.

When the error occurs, it points to this line (348):

## Called when a [param PhantomCamera] is added to the scene.[br]
## [b]Note:[/b] This can only be called internally from a
## [param PhantomCamera] node.
func pcam_added_to_scene(pcam: Node) -> void:
    if is_instance_of(pcam, PhantomCamera2D) or is_instance_of(pcam, PhantomCamera3D): <-- This line 
        _pcam_list.append(pcam)

        if not pcam.tween_on_load:
            pcam.set_has_tweened(self, true) # Skips its tween if it has the highest priority on load

        _find_pcam_with_highest_priority()

    else:
        printerr("This function should only be called from PhantomCamera scripts")

Steps to reproduce

I'm really unsure as it seems to happen randomly upon hitting play. I'm not even using PhantomCamera2D in my game.

(Optional) Minimal reproduction project

No response

ramokz commented 4 months ago

If you have updated the addon from version 0.6.x ⇾ 0.7 within a project, then it's entirely possible that there's some lingering code in one of the hidden Godot directories that hasn't properly updated the name change of phantom_camera_2D to phantom_camera_2d — lowercased “d” at the end. Creating a new project and transferring over the res:// content might solve it then.

If the above doesn't help, would you be able to share a Minimal Reproduction Project (MRP) where that issue happens? Mainly so I can see what setup and logic could potentially trigger this. Haven't come across it myself, and there's not much I can do until I can replicate and verify that a fix would work.

sci-comp commented 3 months ago

Hello,

This is an issue for me as well-- but, in my case at least, I've narrowed the issue down to the use of GDScript's class_name within a Mono build of Godot.

I've seen Nathan Hoad's users (the Godot Dialgue Manger addon) mention this issue as well, though, as far as I know, no one has more information as to a solution or cause, or has created a reproducible project.

A workaround to avoid getting an error is to click build, then play.

image

sci-comp commented 2 months ago

I no longer encounter the error I described after having upgraded into 4.3rc1 (I think around beta1 is when my issue was resolved, I don't know which PR was relevant).

ramokz commented 2 months ago

It was resolved in, if my reading is correct, Godot 4.3 Beta 3 in this PR. Has been a long-standing issue with removing or changing classes in GDScript.

ramokz commented 2 months ago

Closing the issue as Godot 4.3 should be addressing, or at least mitigating, this issue. If it's still being encountered after updating to that Godot version, or later, please do reopen it.