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.
- Right click on the âGameâ tab at the top of the screen
- Click âClose tabâ
- Right click on an open tab and select âAdd tab > Gameâ
- Change view from âFree aspectâ to desired resolution
- Change scale to desired value and hit play
Now the game will start at the proper scale every time.
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.
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.
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.