Stretch mode disabled with centered canvas

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

It’s more of a playground than a strict requirement for my game, but I wish to create a simple framework for rendering:

  • Content is not scaled in any shape or form (Stretch/Mode: disabled).
  • Camera (be it the default, or not) is always of the same size (thus it always shows the same part of canvas).
  • When a bigger screen is used, canvas is presented in the middle of a viewport (VP); currently it’s placed in the top-left corner.

Approaches

Camera It’s always of the window viewport size, thus I cannot limit the canvas being presented, nor where it will be placed on the VP.

Extra VP + set_attach_to_screen_rect VP is not shown in the editor (expected, as specified in the documentation) but it sadly isn’t also visible during runtime. I must be doing something wrong, but I still don’t think it’s the best approach.

Extra VP + Sprite2D/ViewportTexture Works fine because it’s visible in the Editor and I can easily change the sprite position knowing what will be the target resolution.

Extra VP + VPContainer Even easier than before, because I don’t need to create a special texture, and I can just nest one under another.

While the last solution works, there are two issues with it:

##Editor Visibility##
I can’t see all the Canvas items, as their visibility is indirectly controlled by the size of VP. I can deal with that so that during testing I set a very large number and then, during, runtime I set it to FullHD. Still that’s not ideal.

##Reusability##
I am not sure whether I will be able to reuse the “Camera” across different scenes as a VP needs to contain items it will render, hence I am not able to open it after adding to a scene and adding new things to it (in the Editor). Once again - not ideal, but it could work - scenes would be created normally, but in the MAIN scene (which nests a true scene) I could (dynamically) create the VP + VPContainer and add the nested scene which would be taken care by the “fixed camera”.

Any thoughts?