• Godot Help
  • How to get Camera2D to fit the SubViewport it is in?

I'm having trouble with a Node2D scene not being rendered at the right size in a subviewport. I have a simple scene right now I want to draw within a subviewport in my main screen:

I've added it to my main scene inside a subviewport:

The trouble is, when I run it, the scene is drawn without any scaling. I'd like it to scale so that the edges of the camera rectangle exactly match the borders of the camera rectangle. Instead, it seems to be scaled to match the root level viewport.

How do I get my SubviewportContainer to show everything that is in the camera rectangle?

    9 months later

    I was also hoping for a Camera2D to work inside the subviewport but it doesn't seem to. So far I've only been able to manually set the subviewport's size and then move the 2D content so that it is in view.

    • xyz replied to this.

      xyz Well for me Camera2D doesn't work inside a SubViewport.

      kitfox I figured out how to scale for my case. I set the SubViewport size to the desired texture size and then I used size_2d_override to specify a resolution to use and fit into the main size resolution. Also toggled size_2d_override_stretch.

      • xyz replied to this.

        Huraqan You may find it easier to manage if camera is not centered, but aligned topleft. Set its anchor_mode to "Fixed Top Left". Note that camera is not a box. It's only a point. There's nothing to "fit". The box you see drawn in the editor is just reflecting the default main viewport rect for convenience.

          xyz I'm sorry I don't know what you're saying. For me using a Camera2D inside a SubViewport has no effect whatsoever on the rendered output of said SubViewport. So I'm using the solution I posted above to obtain the right scaling within that SubViewport.

          • xyz replied to this.

            Huraqan Well it won't have effect in the editor just like the main viewport camera doesn't have any effect. But they all have effect at runtime. Otherwise the editing of those things would get quite confusing.