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

Decouple PhantomCameraHost from specific PhantomCamera #207

Closed GeneralProtectionFault closed 3 weeks ago

GeneralProtectionFault commented 5 months ago

Project Type

2D

Feature Description

Allow having a camera on the scene w/ a PhantomCameraHost, and dynamically add/remove the PhantomCamera without having to remove/add a new PhantomCameraHost

Use Cases

For clarity, I'm accessing this via C#.
I also am using 2D, but if the same logic is used, I imagine it applies to 3D as well. I set up 2 scenes that I can go between, and add the PhantomCamera & settings/target in code. This works fine.

If, when changing scenes, I free the scene w/ the PhantomCamera & Host, it still works. Going back into the scene a 2nd time works as expected.

However, if I store the scene in memory (a static variable - this is done on a large scene to avoid unacceptable loading time), and simply remove the PhantomCamera from that scene (and remove the scene from the tree), then go back to the stored-in-memory scene again, adding the PhantomCamera on this 2nd tryy causes problems, and this error is thrown:

"Attempt to call function 'queue_redraw' in base 'previously freed' on a null instance."

I essentially figured out that I need to dynamically remove & add the PhantomCameraHost in this situation, which works fine. However, it's not obvious.

Importance

Low - there are workarounds where the proposed feature would just simplify things

Usage

Often - a significant amount of projects can find this useful

(Optional) Proposed Solution

It would be cool if the plugin handled this use case and did not require the removing/adding a fresh PhantomCameraHost. However, I do not know what domino-effects that would have, so if that is a bad idea, I would suggest that an error be thrown at the appropriate times that lets the user know that the PhantomCameraHost needs to be removed/recreated if doing so with the PhantomCamera itself.

ramokz commented 4 months ago

"Attempt to call function 'queue_redraw' in base 'previously freed' on a null instance."

If that error is the only one you're getting, then it might not be a complicated fix. queue_redraw is called manually, but only within the PCam2D script. Suggesting it could be isolated to 2D scenes.

There are two queue_redraw call instances in the script, does the error you're seeing specify which line it's coming from?

ramokz commented 3 weeks ago

Unable to replicate the issue and seems to have gone stale, so closing this issue.