There are three cameras in my scene - Camera1, Camera2, Camera3. I want to have Camera1 as the only current camera. But whenever I remove the "current" tick from Camera2, Camera3 becomes current, and vice versa. No matter what ticks I tick and in what order, I cannot reach the desired state - Camera1 as current, Camera2, and Camera3 as not current. What's going on?
The effective current camera will be the last camera marked current. Where last means lower in the scene tree.
Thus, if you have three cameras: Camera1, Camera2 and Camera3 (in that order), and they are all marked current… The effective current camera is Camera3.
If you unmark Camera3, the effective current camera is Camera2.
If you want Camera1 to be the current, you must unmark both Camera2 and Camera3, because they are after Camera1.
What if there is no Camera marked current? Then Godot picks one, and Godot marks it current. I think this is what is happening to you.
You have three cameras: Camera1, Camera2 and Camera3 (in that order), and only Camera3 is marked current.
If you unmark Camera3, that leaves no camera marked current. Godot picks another camera, in this case Camera2 and Godot marks it current.
Afterwards, you unmark Camera2, that leaves no camera marked current (again). Godot picks another camera (again), in this case Camera3 and Godot marks it current.
So, by unmarking the current camera, the current camera will be going back and forth between Camera2 and Camera3. It will never be Camera1.
What should you do to make Camera1 current?
- Mark Camera1 as current. Which has no immediate effect because some other camera placed after it is current… But the mark is saved.
- Whatever camera is effectively current, unmark it. Now the effective current camera is Camera1
For abstract: avoid leaving no camera marked as current. If you are going to switch cameras, mark the next camera current first, then unmark the old camera.
There are other ways to work with this. I'd advice to make the first camera the default camera. Leave it marked current always. Then you can simply mark another camera current and unmark it when you are done, leaving the effective current camera fallback to the first camera.
From the above follows that you want to sort your cameras by priority (where lower in the scene means higher priority). Leave a "default" camera always marked current as a default fallback. Then you can add other cameras below. Have scripts that marke them current or unmark them when it makes sense. The scripts that handle this does not need to know about the other scripts handling cameras, how many cameras are there, or which camera is the effective current. The effective current camera will be the camera marked current that has more priority (the one lower in the scene tree).
Oh, and if you need cameras that should never be the effective current camera (for example, to get what they see as a texture), they can be before the default one.
One more thing: sometimes it is useful to put a camera in a
RemoteTransform or (
RemoteTransform2D if we are talking 2D). So that the camera can be on one branch of the scene and what it follows in another.
RemoteTransform is also useful if you only want the position, but not the orientation, or viceversa.