Real-time change to Follow Group Array #141
-
Hello Phantom Camera discussions! I'm using PhantomCamera2D to follow two players in a co-op game, but the players ("aloe" and "vera") are destroyed and re-instantiated all the time. Using a script, I erase the follow group array and refill it with the new character nodes. My script is below:
From the print statements I can tell that by the time this function is called, the follow group contains a Freed Object (the Aloe character who gets destroyed). I wrote the
These functions clear the array and fill it with the new nodes, and printing the camera's position shows it to be tracking both characters normally. But nothing draws except the background permanently after Aloe respawns and the array is overwritten. I feel like I'm going against the camera system's design with my functions, but it's the only way I can think of. How can I troubleshoot this, or what would you do to swap out the follow targets? Thanks for any help you can offer! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Update: I have some good news! If you use replace_by() on the node in the Follow Group, there is no need to swap out the array. https://docs.godotengine.org/en/latest/classes/class_node.html#class-node-method-replace-by Hope this can help someone in the future :) |
Beta Was this translation helpful? Give feedback.
-
Hello again! I am back to describe how I've made it work for real. // Make the new Aloe character and add it to the scene.
Aloe temporaryNewAloe = (Aloe)aloeScene.Instantiate();
GetParent().AddChild(temporaryNewAloe);
// Remove old Aloe from the follow group, then queue it for deletion.
phantomCam.Call("erase_follow_group_node", aloe.GetNode<RigidBody2D>("Head"));
aloe.QueueFree();
// Set our Aloe reference to the new Aloe.
aloe = temporaryNewAloe;
// Put in the New Aloe in the follow group.
phantomCam.Call("append_follow_group_node", aloe.GetNode<RigidBody2D>("Head")); So I just needed to base my design more around the intended design of the Phantom Cam functions. As long as the node isn't freed until the end of the frame, Phantom Camera gets to access it and remove it from the follow group. Adding the new node in can happen during the same frame. I experimented more with Also during this journey I found that Thanks for your support! The codebase has been easy to read and that's helped a lot. |
Beta Was this translation helpful? Give feedback.
Hello again!
I am back to describe how I've made it work for real.
Going back to my example of Aloe and Vera,
So I just needed to base my design more around the intended design of the …