Can I set SubViewport stretch mode to canvas_items?

Godot Version

4.3.0 stable

Question

Is it possible to set the stretch mode of a subviewport to canvas_items? I am attempting to develop my game in 640x360 and scale it up with a SubViewport so that I can show text and the UI at a higher resolution but the SubViewport is making my character movements look as it does with Stretch Mode: viewport.

Project settings: 640x360 base res with: Override: 1920x1080, Stretch Mode: canvas_items, Aspect: Keep, Scale: 1, ScaleMode: Fractional.

When I run my game scene directly, the game scales correctly and the enemies move fluidly. If I take my game scene and put it within the following tree:

–SubViewportContainer (Size 1920x1080, Stretch: on, Stretch Shrink: 3)
----SubViewport (Size 640x360)
------Game Scene

Then I update my project settings to a base res of 1920x1080 and run the ViewportContainer scene, the game scales correctly, but the movements in the game are stuttering as if I changed the stretch mode to viewport.

Is there anyway around this?

The best solution I found after looking at the source was to set size_2d_override and size_2d_override_stretch (it’s not very well documented).

What you can do is to set size_2d_override to your base-resolution (in your case 640x360) and size_2d_override_stretch to true. You then set size to the target size/size of the resulting texture you want to output (e.g., 1920x1080).
Of course, you can also use stretch of the SubViewportContainer as you are doing now. But you should lower shrink since the resulting texture is only scaled in ‘canvas-item-mode’ to the size set in the SubViewport (so 1080p with shrink 3 does not scale at all since it’s the base resolution).

1 Like

@pmoosi I could kiss you right now. Was stuck on this for a couple days now and it has been eating away at me. Thank you so much. I did not think size_2d_override would be the answer here but it was.