Camera2D snapping after scene switch

Godot Version

v4.7.1

Question

I have an initial Main Screen scene like this:
Main Screen
→ Player

The following piece of code is the Main Screen script that starts the level.

func _ready() -> void:
	var platform = PLATFORM_SCENE.instantiate()
	platform.position = GameConstants.FIRST_PLATFORM_POS
	add_child(platform)
	platform.freeze()

func _process(_delta: float) -> void:
	if Input.is_action_just_pressed("left") or Input.is_action_just_pressed("right"):
		start_game()

func start_game() -> void:
	GameState.player_position = $Player.position
	get_tree().change_scene_to_file(LEVEL_SCENE_PATH)

As you can see, there is a player, a platform. The player auto jumps on the platform constantly.

The Level scene looks something like this:
Level
→ Player
------> Camera2D

Camera is enabled, smoothing is on, and initially, as soon as the level starts, I see a small snapping, like the camera jumps a bit to a specific location. After that, smoothing is applied as normal. I debugged the heck out of this, printing lots of log lines, but can’t figure out what the snap is.

Disabling the camera in the _ready function of the level removes the snapping (but the camera following as well, obviously). So whatever causes the snap happens after that level initialization.

EDIT: here is a small video of the issue: https://youtube.com/shorts/Iv2R8CHkSWA?feature=share

When the player moves, that is when the scenes change. And that is when the small snap happens. After that, you can notice the camera following smoothly.

A short video showcasing the problem would be great indeed.

Any reason why the camera is not a child of the player?

It is a child of the player, I edited the post now.

Can you not initialize the player before the scene?

It’s usually just an order of operations issue, ensure the position of the camera is set before displaying it and it should prevent the snapping.

added one

I am not sure what you mean by not initialising the player before the scene. The player instances are separate per scene. I just save the last position of the player and use that for the initial position of the new player. This is to achieve a smooth transition from Main Menu to the Level scene.

I’ve tried disabling the camera and enabling it later (in the ready function of the level), but it did not work.

Ok so my guess is that LEVEL_SCENE_PATH is not aligned correctly with the starting scene which gives the impression that the camera is stuttering.

It’s hard to tell from a video but when the game starts, the scene’s position is higher, or at least the platform the player is on is.

So you are suggesting that it is not a camera issue? However, I tested with camera disabled, and there is no snap occuring. Here is a video:

Without being in your editor, it’s always a process of elimination.

Since disabling the camera first has no issue, why not re-enable it once the game starts?

Failing that, I would look into the size of the camera compared to the viewport, it’s limits etc. My next guess would be what the camera deems as the center of the screen: Camera2D — Godot Engine (stable) documentation in English

Nice, thank you so much. The camera was initially offsetted (I think player was its center). This is what it looked like before (check bottom border). After aligning it, the transition is smooth.