How can I bring the player and camera into a new scene?

Godot Version



How can I switch scenes and bring the player and camera into the new scene? From what I’ve read, I can make a camera and player for each scene, But I wanted to avoid this.

Do you have a player scene? That’s certainly the easiest

The easiest way to do this is not to make “multiple players” but by making your player scene (which contains the camera) it’s own file (saving it as a .tscn) and placing him in all levels.
When you load a level, it will then use the camera of the player in the new level.
However if for some reason this is not possible in your use-case (hard to tell as you didn’t provide much info), you can use player.reparent(next_level) (documentation).
To use this you could create the new level, reparent the player to the new level, then delete the old one. Using some sort of transition to hide the player vanishing would be optimal.
Hope this helps.


To build upon this, one of the ways you can manage things like movement controls, HUDs, etc is to make them part of the player scene.

Sometimes (like in our game) you change between walking or piloting modes, and so we have different player scenes depending on situation and then drop the appropriate one into the map/level scene.

There are several ways to achieve that, and which one you use will depend largely on the overall structure of your game. I use a combination of techniques that work well with my game structure, and they revolve around using a main scene as the parent for everything.

The camera and the player are children of this main scene. When a new level/scene is created, the player and camera are parented to that scene for the duration that the scene exists, and a reference to each of those objects is passed to the new scene. When the level/scene is to be terminated, the player and camera are reparented back to the main scene so they won’t be terminated alongside the level scene.