Issues with Node References and Scene Transitions

Godot Version

4.3

Question

I’m facing a problem with managing nodes and scene transitions in my project. Here’s a summary of the situation:

Setup:

  • The game is played with a main player character and a ghost

  • The Player and Spirit each have their own components for movement and activation.

-The player and spirit nodes are encapsulated within a parent node called PlayerAndGhost.

-An autoload global script named ControlManager is used to switch control between the Player and Spirit nodes and to update the active camera.

-I made an Area2D node that changes the scene to another PackedScene through an export variable I add through the inspector

Problem:

When running scenes independently, the ControlManager script correctly switches control between Player and Spirit and updates the camera.
However, when transitioning to a new scene where the PlayerAndGhost node is already in, I encounter the following error: Attempt to call function ‘get_node’ in base ‘previously freed’ on a null instance.

Try putting an if statement for is_instance_valid() and put the get_node code inside this if statement.

if is_instance_valid(get_node("nodename"))
	get_node("nodename").method()

I’m assuming you’re trying to call a method on a node that is freed and is yet to be instanced again. Using this if statement skip execution of the method until the node is back in the scene

So adding it within the control manager made it so that it doesn’t crash now when I switch but they still freeze and can’t move
Did I implement it right