Resize RenderTexture at Runtime

Hi there,

I’m wondering if there’s a way to resize a RenderTexture while the game is playing.

If I try and modify the height/width during the game, it tells me that

Resizing of render texture that is loaded not supported!

I basically want to match a RenderTexture’s resolution to the screen height and width at run time. Is there a way to access it prior to loading it in the scene? It seems that as soon as I access it, it loads (obviously), and then I can’t programatically modify it.

Any and all help appreciated!

You can’t resize a render texture but you can set a new one that is the size you need.

If you use the “camera.targetTexture” property (Unity Pro only) you can do :

if ( camera.targetTexture != null ) {
	camera.targetTexture.Release( );
}

camera.targetTexture = new RenderTexture( Screen.width, Screen.height, 24 );

Well, guys the answer by @thebmxeur is wrong if you release the render texture you can modify the width and height… here is the proper version:

  void Resize(RenderTexture renderTexture, int width, int height) {
             if (renderTexture) {
                renderTexture.Release();
                renderTexture.width = width;
                renderTexture.height = height; 
            }
    }
1 Like