- Home /
How to keep Render Texture aspect ratio from perspective camera when window is resized?
Hello everyone. I've been struggling with this issue a lot. Whenever I have the display view at free aspect, I can't seem to keep the aspect ratio of the Render Texture at a fixed ratio. I can't lock the aspect ratio of the app window either because Unity still has not fixed the bug where if I call SetResolution() method and go fullscreen, the mouse input position is screwed up. Attached are the images of preferred aspect ratio Render Texture and the Render Texture after resizing the window. Can anyone help me with this issue please? Thank you in advance.
How are you creating the RenderTexture? If you wanted it to have a fixed aspect ratio, surely you would set it to a fixed resolution/resolution in terms of the same variable?
Answer by Freznosis · Aug 29, 2017 at 09:01 AM
I know this is a rather old post but just in case someone comes along later looking at this question since Unity STILL hasn't fixed this bug it is good to first modify your Camera's aspect ratio before rendering it to a texture. The example below is a good starting point.
Camera.main.aspect = ScreenshotWidth / ScreenshotHeight;
Camera.Render();
//Good idea to wait for the end of the frame so that you can be sure your aspect change was rendered
yield return WaitForEndOfFrame();
//Do snapshot stuff here
renderTextureToTexture.Apply();
//Reset your camera's aspect after reading your screenshot
Camera.main.ResetAspect();
Your answer
Follow this Question
Related Questions
How to get a camera to render to render texture at a custom aspect ratio. 1 Answer
Graphics.Blit scale 1 Answer
Canvas aspect ratio 1 Answer
RenderTarget in scripts 0 Answers
How to get RenderTexture non-square? 2 Answers