Unable to Access Variables on Scene Instanced via Script

Godot Version

Godot 4.2.1


My main scene starts with an instance of my player placed via the editor and all the associated scripts work fine. Later, when the player is deleted and instantiated via code, the once functioning scripts are no longer able to access any variables of the player and crash immediately, throwing the same Invalid get index 'variable_name' (on base: 'CharacterBody3D'). error every time. I am having nearly the exact same issue as this reddit post, but I can’t figure out my issue.

Without seeing any code I can only speculate, but from what you told us, it seems like you remove / Free the player instance. This means that all the references to the player instance will be null. You need to find your player instance again as soon as you instantiate it.

The references to the player cannot be null, as the scripts that are failing are children of the player, and they reference it with a $path directly to it

Can you show this code? It’s difficult to pinpoint the problem source without it.