Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by ABerlemont · Dec 19, 2018 at 01:10 PM · gamescaleview

Game view scale on compilation/play

Something that has been going on for some time in Unity since they added the Scaling of the game view is that sometimes after compilation and/or when pressing the play button the scale change for no reason (zoom in the game view). Restarting unity doesn't fix this. It seems to always go to 0.55 in scale.

Am I the only one that have this problem ? Did anyone managed to understand why it happens and how to solve this ?

Thanks for the help

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image svendkiloo · Dec 19, 2018 at 01:59 PM 0
Share

I get it as well. It seems to vary depending on which resolution you choose. It seems to scale such that the resolution matches your PCs resolution, or something along those lines. So if you choose a high resolution (e.g. 1125x2436) it zooms in so you can only see some of the screen, but if you choose a low resolution (e.g. 800x480) it zooms out so the camera view only takes up a fraction of the game window.

avatar image ABerlemont svendkiloo · Dec 19, 2018 at 02:04 PM 0
Share

but somehow doesn't happen all the time ... even when I setup the editor and prefered resolution the same way across projects/computers.
fun fact : it also does it when applying "free aspect" which,to me, doesn't make sense at all.
Thanks for the insight.

5 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by ABerlemont · Dec 19, 2018 at 02:06 PM

It seems that changing the layout through the "saved layout" menu (top right of the editor) temporary fix this issue.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image subzer0 · Jan 12, 2019 at 02:22 PM 0
Share

@ABerlemont can you please tell me how you solve it ? I went to layout button in the top right corner and saved the layout. But it is still zoo$$anonymous$$g in on play mode.

avatar image ABerlemont subzer0 · Jan 12, 2019 at 07:03 PM 1
Share

I meant: change the layout selecting any other than the one you are using will refresh the editor and fix the issue
You can, for example, save your current layout then switch to another one and then come back to it using the layout menu

avatar image subzer0 ABerlemont · Jan 13, 2019 at 09:13 AM 0
Share

Ok, thanks ! It worked.

Show more comments
avatar image svendkiloo · Mar 14, 2019 at 07:32 AM 0
Share

This used to work for me, but recently I couldn't get it to fix it. As I don't need a fixed resolution at the moment, I've just set it to a fixed scale ins$$anonymous$$d and then the problem doesn't happen.

avatar image
2

Answer by svendkiloo · Mar 14, 2019 at 07:34 AM

EDIT: This seems to now have been fixed in 2019.1.8:

 Editor: Fixed game view scale in play mode for mobile platforms. (1140742, 1151179)

https://unity3d.com/unity/whats-new/2019.1.8


Also fixed or planned fixed for some other major Unity versions: https://issuetracker.unity3d.com/issues/game-tab-window-rescales-when-entering-the-play-mode?_ga=2.6018931.1353564765.1561964524-1323957048.1539005405


An alternative solution, if you don't need to have the game view set to a certain resolution, is to set it instead to a certain aspect ratio. Then the scaling problem doesn't seem to occur.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JeremyBerube · Dec 07, 2019 at 05:01 PM 0
Share

The alternative solution of using an aspect ratio did the trick for me. Thanks!

avatar image
2

Answer by bmulla · Mar 14, 2019 at 07:40 PM

Just use this code snippet http://answers.unity.com/answers/1612575/view.html

  #if UNITY_EDITOR
  void Awake()
  {
      SetGameViewScale();
  }
  
  void SetGameViewScale()
  {
      System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
      System.Type type = assembly.GetType("UnityEditor.GameView");
      UnityEditor.EditorWindow v = UnityEditor.EditorWindow.GetWindow(type);
  
      var defScaleField = type.GetField("m_defaultScale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
  
      //whatever scale you want when you click on play
      float defaultScale = 0.1f;
  
      var areaField = type.GetField("m_ZoomArea", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
      var areaObj = areaField.GetValue(v);
  
      var scaleField = areaObj.GetType().GetField("m_Scale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
      scaleField.SetValue(areaObj, new Vector2(defaultScale, defaultScale));
  }
  #endif
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by Flexford · Apr 20, 2019 at 10:28 PM

Improved code:

 using System;
 using System.Reflection;
 using UnityEditor;
 using UnityEngine;
 using Object = UnityEngine.Object;
 
 [InitializeOnLoad]
 public static class FixResolutionScale
 {
     static FixResolutionScale()
     {
         EditorApplication.playModeStateChanged += OnPlayStateChanged;
         SetGameViewScale();
     }
 
     private static void OnPlayStateChanged(PlayModeStateChange playModeStateChange)
     {
         SetGameViewScale();
     }
 
     private static void SetGameViewScale()
     {
         Type gameViewType = GetGameViewType();
         EditorWindow gameViewWindow = GetGameViewWindow(gameViewType);
 
         if (gameViewWindow == null)
         {
             Debug.LogError("GameView is null!");
             return;
         }
  
         var defScaleField = gameViewType.GetField("m_defaultScale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
  
         //whatever scale you want when you click on play
         float defaultScale = 0.1f;
  
         var areaField = gameViewType.GetField("m_ZoomArea", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
         var areaObj = areaField.GetValue(gameViewWindow);
  
         var scaleField = areaObj.GetType().GetField("m_Scale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
         scaleField.SetValue(areaObj, new Vector2(defaultScale, defaultScale));
     }
 
     private static Type GetGameViewType()
     {
         Assembly unityEditorAssembly = typeof(EditorWindow).Assembly;
         Type gameViewType = unityEditorAssembly.GetType("UnityEditor.GameView");
         return gameViewType;
     }
 
     private static EditorWindow GetGameViewWindow(Type gameViewType)
     {
         Object[] obj = Resources.FindObjectsOfTypeAll(gameViewType);
         if (obj.Length > 0)
         {
             return obj[0] as EditorWindow;
         }
         return null;
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wmadwand · May 21, 2019 at 06:26 AM 0
Share

Very nice, thank you!

avatar image nayakshasvat · May 25, 2019 at 05:55 AM 0
Share

Awesome! It worked Thanks!

avatar image OGNE · Jun 20, 2019 at 09:18 AM 0
Share

Worked for me. thanks

avatar image
1

Answer by hojjat-reyhane · Jun 19, 2019 at 02:27 AM

A fix to previous solution. In my case if I edit the scripts, unity 2019.1.5 changes the scale of game window. So ... Just add this to your project.

 using System;
 using System.Reflection;
 using UnityEditor;
 using UnityEngine;
 using Object = UnityEngine.Object;
 
 [InitializeOnLoad]
 [ExecuteInEditMode]
 public class FixGameWindowScaleBug
 {
     private static bool mUpdate = false;
     
     static FixGameWindowScaleBug()
     {
         EditorApplication.update += update;
         EditorApplication.delayCall += delayCall;
         SetGameViewScale();
     }
     
     private static void delayCall()
     {
         mUpdate = true;
     }
     
     private static void update()
     {
         if (mUpdate)
         {
             SetGameViewScale();
             mUpdate = false;
         }
     }
 
     private static void SetGameViewScale()
     {
         Type gameViewType = GetGameViewType();
         EditorWindow gameViewWindow = GetGameViewWindow(gameViewType);
 
         if (gameViewWindow == null)
         {
             Debug.LogError("GameView is null!");
             return;
         }
 
         var defScaleField = gameViewType.GetField("m_defaultScale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
 
         //whatever scale you want when you click on play
         float defaultScale = 0.1f;
 
         var areaField = gameViewType.GetField("m_ZoomArea", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
         var areaObj = areaField.GetValue(gameViewWindow);
 
         var scaleField = areaObj.GetType().GetField("m_Scale", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
         scaleField.SetValue(areaObj, new Vector2(defaultScale, defaultScale));
     }
 
     private static Type GetGameViewType()
     {
         Assembly unityEditorAssembly = typeof(EditorWindow).Assembly;
         Type gameViewType = unityEditorAssembly.GetType("UnityEditor.GameView");
         return gameViewType;
     }
 
     private static EditorWindow GetGameViewWindow(Type gameViewType)
     {
         Object[] obj = Resources.FindObjectsOfTypeAll(gameViewType);
         if (obj.Length > 0)
         {
             return obj[0] as EditorWindow;
         }
         return null;
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Squize · Sep 18, 2019 at 11:11 AM 0
Share

Excellent! Thanks for posting this mate.

avatar image svendkiloo Squize · Sep 18, 2019 at 01:04 PM 0
Share

Of course, if you can update to latest Unity, where it's fixed (see my answer), then you don't need to add it :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

140 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with overhead view game 1 Answer

Unity Scaling for Android on 5.5. 0 Answers

Is there any way to get Debug.DrawLine() to display in the game view without other gizmos? 2 Answers

My game shows weird errors in game view 1 Answer

Scene is suddenly super small,Scene is suddenly super small on reload 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges