Add GameView API for changing the resolution and scale

Please consider exposing some public APIs to allow us to change the resolution of the GameView, as well as the scale setting.

This is an important feature for Play Mode Tests if you want to take screenshots with a fixed resolution and compare them to a baseline.

The ScreenCapture.CaptureScreenshot method takes a screenshot at the currently active resolution, which happens to be the GameView resolution if you’re running in the Editor.

There are workarounds, but no really good solution. You can render into a RenderTexture with a fixed size, but that will can produce different results (no UI, possibly different effects, view port, occlusion mesh settings). Or you can use reflection to set the resolution, but that is an unstable and breaks between versions.

4 Likes

There is useful thread on forum with solution.
You can use code like this to change Game View Resolutiion during play mode

var gvWndType = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
var gvWnd = EditorWindow.GetWindow(gvWndType);
var SizeSelectionCallback = gvWndType.GetMethod("SizeSelectionCallback", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

SizeSelectionCallback.Invoke(gvWnd, new object[] { 0, null });

Soure forum thread:

1 Like