I'm trying to learn the UI part of Unity and the use case I want to achieve is to setup a windowed user interface which looks like Unity or Blender's one (simplified): with one or more 3D views in it + some canvas with 2D GUI.

What I've tried so far is to make it using a canvas with an image in it, which itself has a raw image component. The raw image has a render texture as 'texture'.

But doing that, the texture is stretched when the rect transform of the image is changing. So I don't know how to handle that if the size and position of the view is changing (I've seen the minimap tutorials but here the size is static).

Another way could be to limit one or several main cameras 'viewport rect'.

But so far I don't know which is the best approach in order to set it up efficiently and have no difficulties to handle camera's movements, centered in the view, etc.

What is the good way to do that?

Edit: following the advice of DMGregory, it works perfectly

enter image description here

The idea is to update the camera's rect with something like this:

var anchorMin = parenRectTransform.anchorMin;
var anchorMax = parenRectTransform.anchorMax;

Camera.rect = new Rect( anchorMin, anchorMax - anchorMin );

Here parentRectTransform is the rect transform of the parent of my 3D view, so that the anchor's position and size are relative to the global space (screen).

The other approach using a render texture is not possible as its size cannot be changed at run time (the only possibility was to recreate one each time).


1 Answer 1


Myself, I'd see how far I could get with cameras' viewport rects first. This can avoid some overhead of rendering to a RenderTexture first then displaying it, with all the possible resizing & sample-mismatching issues that can come with that.

Doing it this way, you can also assign UI to each pane by using a Canvas set to "Screen Space — Camera" pointing at the camera for that pane, and it will scale correctly as the viewport changes.

The render-to-texture / display via RawImage method will work too, and will be desirable for certain kinds of effects, but I think it's more complicated than what you're likely to need.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .