Search Unity

Feedback Add GameView API for changing the resolution and scale

Discussion in 'Editor & General Support' started by DrummerB, May 7, 2020.

  1. DrummerB

    DrummerB

    Joined:
    Dec 19, 2013
    Posts:
    135
    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.
     
  2. myuemelianchenko

    myuemelianchenko

    Joined:
    May 1, 2020
    Posts:
    1
    There is useful thread on forum with solution.
    You can use code like this to change Game View Resolutiion during play mode

    Code (CSharp):
    1.  
    2. var gvWndType = typeof(Editor).Assembly.GetType("UnityEditor.GameView");
    3. var gvWnd = EditorWindow.GetWindow(gvWndType);
    4. var SizeSelectionCallback = gvWndType.GetMethod("SizeSelectionCallback", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    5.  
    6. SizeSelectionCallback.Invoke(gvWnd, new object[] { 0, null });
    7.  
    Soure forum thread:
    https://answers.unity.com/questions/956123/add-and-select-game-view-resolution.html
     
    Thaina likes this.