Greetings! I'm new to Godot and I found today that I can see 2D nodes in runtime even if I don' place a Camera2D in the scene contrarily to what happens in 3D (with no Camera3D you cannot see 3D models).

I'm making a game that switches between 2D and 3D and I want to turn off the Camera2D when player is in 3D mode and vice versa but I can always see the 2D tilemaps and sprites over the 3D world. I noticed that I can hide them with the CanvasItem.Visible variable but I'm trying to understand this behavior.

Thank you in advance and excuse me for my bad English.

My guess is that in 2D there's only one view, unless you are doing some kind of special effect, so requiring a camera is considered redundant.

    DaveTheCoder Thank you for your answer 🙂

    So is there a way to hide 2D nodes from Camera2D other than disabling CanvasItem.Visibe in the sprites/tilemaps? Something I can do from the camera or configuration side and not from the world itself. What I have done to achieve this effect feels a little unclean:

    private void Set2DCamera()
        {
            _camera_is_2d = true;
            _map.Visible = true;
            _camera2D.Enabled = true;
            _camera3D.Current = false;
            _camera2D.MakeCurrent();
        }
    
        private void Set3DCamera()
        {
            _camera_is_2d = false;
            _map.Visible = false;
            _camera2D.Enabled = false;
            _camera3D.Current = true;
            _camera3D.MakeCurrent();
        }

    This would be problematic if I implement a split screen coop as it would disable the visibility of the world for all players not only for those who are in 3D mode.

    I think the best solution to these problem is to use Viewports.
    You would put 2D world in one viewport and 3D world in another viewport and change the visibility of the viewports based on the current mode.
    And for split screen you would put just the cameras in viewports, because the world (i.e., nodes, sprites, etc.) will be shared between cameras of the same mode.

      To answer the question in the title. Because the root of the project is always a viewport. And because by default the main scene is rendered into the viewport. Without a camera it's the main scenes 2D viewport bounds. Mind, this is likely an oversimplification. But should get the idea across.

        LoipesMas Thank you for your answer. Sorry if I don't understand but I have already tried view viewports (or SubViewports and SubViewportContainers as it has changed in Godot 4 and the tutorial is a bit outdated) and the problem is the same: If I turn off the visibility of a viewport it will disappear from all cameras inside it, making it impossible to have one player in 2D mode and the other in 3D mode at the same time.

          Megalomaniak Thank you! I was very confused about this behavior but knowing the root is a viewport helps me understand 🙂 still feels kind of weird that it displays the 2D world when I actually have a Camera3D active, is giving me trouble jumping to 3D world without disabling the 2D world for all players.

            Wulfara
            My bad, is misremembered some things.
            To have viewports share the world, you need to do it manually.
            Here's a basic scene that has that set up:

            viewports.zip
            800B

            We have viewport 2DWorld that is not being rendered (because it's not in any SubViewportContainer) and one SubViewportContainer for each player. Players' viewports need to set their 2d worlds to that of 2DWorld viewport. Unfortunately, this can be only done through code.
            And because the actual nodes are in a separate viewport, player's viewport can be hidden, without hiding the world for the other player.

            Here's a tutorial. It was made for Godot 3, but the general principals still hold.

            I hope this helps!

              Wulfara still feels kind of weird that it displays the 2D world when I actually have a Camera3D active, is giving me trouble jumping to 3D world without disabling the 2D world for all players.

              Well the other side of it is that 3D games often have HUDs. You'd use the 2D editor for creating your HUD usually and a HUD just doesn't need a camera, only layouting features such as the bounds and anchors, etc.

                LoipesMas Thank you very much! That is very helpful and I think I have a better understanding of viewports now. That really seems the key to what I'm trying to achieve here. I'll try it as soon as I can.
                Greetings 🙂

                a month later