How to change the default camera

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sygi

I have a very simple 2D scene with a single sprite. I would like to be able to change the default camera. I added a Camera2D, moved it and selected as “current”. In the main view, I can see the boundaries of the camera to change. However, when I run, the original camera (starting at 0, 0) is used.

I tried changing the camera settings and making the camera a child of different nodes, but nothing seems to help.

The scene in question:

[gd_scene load_steps=3 format=2]

[ext_resource path="res://KinematicBody2D.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]

[node name="Node2D" type="Node2D"]

[node name="CanvasLayer" type="CanvasLayer" parent="."]

[node name="KinematicBody2D" type="KinematicBody2D" parent="CanvasLayer"]
position = Vector2( 119.503, 146.059 )
script = ExtResource( 1 )

[node name="Sprite" type="Sprite" parent="CanvasLayer/KinematicBody2D"]
show_behind_parent = true
position = Vector2( -2.5932, -9.77798 )
scale = Vector2( 1.22236, 1.40821 )
texture = ExtResource( 2 )

[node name="Camera2D" type="Camera2D" parent="CanvasLayer/KinematicBody2D"]
position = Vector2( -278.128, 117.191 )
current = true
:bust_in_silhouette: Reply From: Calinou

Your 2D nodes are children of a CanvasLayer, which means they won’t move along with the camera. To solve this, move your 2D nodes out of the CanvasLayer.

Thanks, removing the CanvasLayer made the camera work.

However, note that I don’t really move anything here, just trying to use a different camera. Am I right that setting a camera “current” never makes sense inside the CanvasLayer? If so, would a warning notification be in place whenever I set “current” on a camera inside a CanvasLayer? (I can add a bug/proposal if so)

Is there, actually, a way to make this work as intended, that is: put the actual objects inside a CanvasLayer and make the camera to follow one of them, without being its child?

sygi | 2020-12-30 09:28