- Home /
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!
Answer by thebmxeur · Aug 14, 2014 at 07:48 PM
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 );
Thanks, this answer was really useful. Don't forget to reassign the texture to the mesh renderer!