Game Window Scale

yup.

This problem have for Unity 2022.3.8f1, with select platform Android. For PC - all ok.
I have the scale set to a value of 1.3.
This happens even when using the “Aspect” resolution. It still doesn’t fit in the area of my window, which is very annoying.

@Flexford , it’s been half a year since you’ve been in this forum, but just in case you ever happen to come back i want you to know how really helpful this script is to me and that i appreciate that you shared your work here.

I have found a working workaround for this issue for anyone who has the same problem.

  1. Right click on the “Game” tab at the top of the screen
  2. Click “Close tab”
  3. Right click on an open tab and select “Add tab > Game”
  4. Change view from “Free aspect” to desired resolution
  5. Change scale to desired value and hit play

Now the game will start at the proper scale every time.

1 Like

For editor problems of all stripes, sometimes it helps to reset the Layout to Default in the top right then apply a more specific fix.

2 Likes

This was the fix we were looking for. Thank you kindly!

Just right click the Game tab, close it, and re-open the game window, the problem will be fixed.

1 Like

Just stumbled upon this issue after switching monitors on 2022.3.36f1. The issue indeed seems to be related to Windows display scaling, as @egicoro mentioned (works fine on 100%, but scales the game window when set to 150%).

Thanks @Flexford for the code!
Here is a slightly updated version that includes caching and multiple game window support:

using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Scripts.Utility.Editor
{
	[InitializeOnLoad]
	public static class GameWindowScaler // Tested on 2022.3.36f1
	{
		private static readonly Vector2 DefaultScale = new(DEFAULT_SCALE, DEFAULT_SCALE);

		private static Type _viewType;
		private static Type ViewType => _viewType ??= typeof(EditorWindow).Assembly.GetType("UnityEditor.GameView");
		
		private static FieldInfo _zoomField;
		private static FieldInfo ZoomField => _zoomField ??= ViewType.GetField("m_ZoomArea", BINDING_FLAGS);

		private static FieldInfo _scaleField;
		private static FieldInfo ScaleField => _scaleField ??= ZoomField.FieldType.GetField("m_Scale", BINDING_FLAGS);

		private const float DEFAULT_SCALE = .1f;
		private const BindingFlags BINDING_FLAGS = BindingFlags.Instance | BindingFlags.NonPublic;

		static GameWindowScaler()
		{
			ScaleGameWindows();
			EditorApplication.playModeStateChanged += OnPlayStateChanged;
		}

		private static void ScaleGameWindows()
		{
			Object[] gameWindows = Resources.FindObjectsOfTypeAll(ViewType);

			if (gameWindows.Length == 0)
				return;

			foreach (object gameWindow in gameWindows)
			{
				object scaleValue = ZoomField.GetValue(gameWindow);
				ScaleField.SetValue(scaleValue, DefaultScale);
			}
		}
	
		private static void OnPlayStateChanged(PlayModeStateChange _)
		{
			ScaleGameWindows();
		}
	}
}

Adjust DEFAULT_SCALE if necessary; 0.1 works great for me.