The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have a player character that I want to be able to seamlessly transition between different scenes. The way I tried to do this was by using an autoload script. There was a variable "player" that stored the player node, and whenever the player passes a certain location, the autoload changes the scene and adds the player variable to the new scene root using add_child(). However, whenever this function runs the game instantly crashes with no error message. I can post a gif of what happens with my specific code if that helps. Thanks in advance! :)
Edit: I have found out my problem is due to the player variable becoming "Deleted Object" when I change scenes. This is because the variable is pointing to a specific node in a specific scene. So what I want to know, is how can I "save" the player node as a scene that I can instance in the next scene? Thanks! :)

in Engine by (67 points)
edited by

1 Answer

+4 votes

So I assume, 2 things:

  • either you are loosing a reference to player instance
  • or you are deleting player with a scene, because it's connected

The way I would do it, is to store a reference to a player somewhere in a singleton, or add it to the root tree temporarily and then, when a new scene is loaded, add it as a child. But the important thing here is that you need to call remove_child first like this:

# or if the parent of player is current scene just remove_child(player)

# store player reference

# after a new scene is loaded
by (22 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.