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.23k stars 75 forks source link

Persistent error - get_tree: Parameter "data.tree" is null. #377

Closed witchpiggie closed 3 weeks ago

witchpiggie commented 2 months ago

Issue description

Receive this error when using PhantomCamera 0.7.3 in Godot 4.3 get_tree: Parameter "data.tree" is null. <C++ Source> ./scene/main/node.h:446 @ get_tree()

Steps to reproduce

(Optional) Minimal reproduction project

min.project.zip

jktrctt commented 1 month ago

I've been having this same issue with my project for weeks after upgrading to 4.3. It's kind of driving me nuts.

jktrctt commented 1 month ago

I've been trying to figure out what's causing this error. Kind of strange, but:

My scene throws the error in the editor and in game. If I delete the PhantomCamera2D from the scene (leaving the PhantomCameraHost in the scene), it still throws the error, even after reloading the project. If I remove the PhantomCameraHost from the scene, it still throws the error until I Reload current project, then the error disappears. Re-adding the PhantomCameraHost makes the error come back. Strangely, testing the game in the editor works fine ... I haven't noticed anything strange. The error is definitely cause for concern, though. The error appears at runtime in the script line that instantiates the scene with the PhantomCamera2D and the PhantomCameraHost in it. It happens in both scenes with those nodes in my project.

ValFan771 commented 1 month ago

For me it is even weirder. I added the addon to my project but I did not yet configure any cameras nor added a PhantomCameraHost to my scene yet I still get the error message during godot startup or when launching the project itself.

When I try to disable the autoload plugin in the project settings I am still getting the error. The project itself works fine, just as Jktrctt said, it is slightly concerning.

hunterloftis commented 3 weeks ago

Here's a minimal reproduction with a totally-vanilla Godot 4.3 project, no need for PhantomCamera or any other changes. It seems to be triggered by setting physics interpolation to Off on any Camera2D.

Upon opening the project: image

Upon starting the scene: image

bug_cam_physics.zip

Resetting physics interpolation clears the error.

ramokz commented 3 weeks ago

It seems to be triggered by setting physics interpolation to Off on any Camera2D.

That seems to be it, yes!

It's very weird, since the error code in the editor points to it being a null pointer issue when looking up the line in node.h in Godot's source code. Looked and tested around for a while, but could never figure out where it would have come from. Seems to have been a red herring this whole time…

So the good news is that removing the error is pretty trivial, basically just changing a number in the PCamHost file, ~however the less good news is that it now produces a persistent warning instead:~ image

~Looking through the engine source code, and doing a few tests, it seems like there isn't really a way to avoid this one as it appears to be triggered whenever physics interpolation is enabled from the Project Settings — happy to be proven wrong though!~

For those wanting a quick DIY fix before the next release, you can just update the value from 2 to 0 on line 486 inside phantom_camera_host.gd:

# camera_2d.set("physics_interpolation_mode", 2)
camera_2d.set("physics_interpolation_mode", 0)

Edit: Removing the follow-up Engine warning should resolved by adding these lines to both conditional statements of _physics_based (line 498):

if ProjectSettings.get_setting("physics/common/physics_interpolation"):
  camera_2d.process_callback = Camera2D.CAMERA2D_PROCESS_PHYSICS
else:
  camera_2d.process_callback = Camera2D.CAMERA2D_PROCESS_IDLE