Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Maaalene · Aug 20, 2021 at 01:06 PM · resolutionsettingsviewport

Is there a setting to default the Editor Game View to a specific aspect ratio?

I am trying to get the game view fixed to portrait mode. While this of course works on my computer, I can't find a way to set this for colleagues so that other people who access the repository will automatically see the game in portrait mode as well.

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 Vivien_Lynn · Aug 20, 2021 at 03:54 PM 1
Share

I don't know if there is a way to do that. I assume the set resolution or apsect ratio in the editor is only for your editor exclusively. What you can do for now is, to check if the aspect ratio of the game matches your desired ratio, if that is not the case, throw a Debug.Log Message that informs your colleagues that they have to add the ratio to their game view.

avatar image Maaalene Vivien_Lynn · Aug 20, 2021 at 04:08 PM 0
Share

Thanks for your reply! Could you tell me how I can check the aspect ratio of the game in the editor view?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Vivien_Lynn · Aug 21, 2021 at 11:13 AM

I looked further into it and I found this link that might help you: https://answers.unity.com/questions/956123/add-and-select-game-view-resolution.html

I also tried to work out a simpler solution, that does not require actual Editor scripts. This solution grew quite big, since it needs a lot of commentary because it is not so straight forward what is happening under the hood. I attached my script below.

What my script essentially does is, it looks for the current aspect ratio of the game view, and if it is not set to 9:16, a Debug Message informs the programmer that they have to set the game view to 9:16.

It seems that Unity has some rounding issues when it comes to calculating the aspect ratio of the game view. So instead of checking if the current ratio is exactly 9:16 (=0.5625), I rather check if it is close to that number.

I can imagine that Unity returns different results on different computers, that's why I also added a debug mode, that allows to see what ratio Unity finds on your machine. I hope that my code or the link delivers a valid solution for you.

 using System.Collections.Generic;
 using UnityEngine;
 using System.Linq;
 
 // Description:
 // Attach this script to a GameObject in your Project
 // This script will ensure that the game view window is always set to an aspect ratio of 9:16
 // It checks the current aspect ratio and informs the programmer with a debug message if the aspect ratio is not set to 9:16
 //
 //
 //
 // Summary:
 // When the game view ratio is set to 9:16, it is expected that the calculation '(float)Screen.width / (float)Screen.height' returns 9:16 = 0.5625
 // This is not always the case (I am unsure why). 
 // When you set your game view ratio to 9:16 and you squeeze the view horizontally (left/right), to the point that Unity draws letter boxes (gray bars
 // on top and bottom to maintain a ratio of 9:16), then the calculation returns values that are close to 0.5625, but not exact.
 // In my tests it returns values between 0.5611111 and 0.5638298
 // That is why I check for a ratio range in Update(), instead of just looking for (float)Screen.width / (float)Screen.height == 9f/16f
 //
 // If you want to find out what values your Editor returns for (float)Screen.width / (float)Screen.height, first set your game view window to 9:16.
 // Enable the debugMode bool in the inspector and play around with the width of your game view 
 // Slowly stretch the windows enough so that Unity draws Pillar boxes (gray bars left and right), and squeeze it enough to force Unity to draw letter boxes 
 // (gray bars on top and bottom)
 // After you have done this, rightclick on the script in the inspector and select "Print MinMax" to print the smallest and biggest ratio that Unity detected
 // Use these numbers to set your min max values in the if-statment.
 // For me that is 0.5611111 and 0.5638298
 // So to make sure I dont trigger that if-statmen accidentally, I set my range from 0.560 to 0.564
 
 [ExecuteInEditMode]
 public class AspectRatioChecker : MonoBehaviour
 {
     [Tooltip("Debug Mode: Use this to determent a better ratio range for your game view (Read Summary inside this script for more information).")]
     [SerializeField] private bool debugMode = false;
 
     private List<float> ratios = new List<float>();
 
 
     private void Update()
     {
         // Only do this in Editor and while not in Playmode
         if (Application.isPlaying) return;
 
         Debug.Log("Is Running!");
 
         float ratio = (float)Screen.width / (float)Screen.height;
 
         // Check if Aspect ratio is 9:16 (or very close to it)
         if (0.560 <= ratio 
             && ratio <= 0.564)
         {
             // We are in desired Range (very close to 9:16)
         }
         else
         {
             // Not in desired Range
             Debug.Log($"Wrong aspect ratio deteced. Please set the aspect ratio of the game view to 9:16");
         }
 
 
         // Debug Mode
         if (debugMode)
         {
             // To prevent the list from growing too big
             if (ratios.Count < 1000)
             {
                 ratios.Add(ratio);
                 Debug.Log($"Ratio: {ratio} " + '\n' +
                     $"List length: {ratios.Count}/1.000");
             }
             else
             {
                 Debug.Log($"Ratio List already holds 1000 values. Please clear the List or disable DebugMode.");
             }
         }
         else
         {
             ratios.Clear();
         }
     }
 
     [ContextMenu("Print MinMax")]
     private void PrintMinMax()
     {
         Debug.Log($"##### Elements in List: {ratios.Count} #####");
         Debug.Log($"Min: {ratios.AsQueryable().Min()}");
         Debug.Log($"Max: {ratios.AsQueryable().Max()}");
     }
 
 
     [ContextMenu("Empty List")]
     private void EmptyList()
     {
         Debug.Log($"List cleared!");
         ratios.Clear();
     }
 }
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 Maaalene · Aug 23, 2021 at 09:48 AM 0
Share

Thanks a lot! I ended up checking the ratio as you suggested but I only call it when the Editor enters the Playmode. Here is the code for that for anyone who stumbles upon the same problem.

 using UnityEngine;
 using UnityEditor;
 
 [InitializeOnLoad]
 public static class AspectRatioChecker
 {
     // register an event handler when the class is initialized
     static AspectRatioChecker()
     {
         EditorApplication.playModeStateChanged += CheckGameView;
     }
 
     private static void CheckGameView(PlayModeStateChange state)
     {
         if (state == PlayModeStateChange.EnteredPlayMode)
         {
             float ratio = (float)Screen.width / (float)Screen.height;
             ...
         }
     }
 }
avatar image
0

Answer by qsp18 · Aug 20, 2021 at 05:49 PM

In Game-View one centimeter below there is the word "Display 1". Right of that there is the word "Free Aspect". Click on it and select Aspect Ratio

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 Maaalene · Aug 20, 2021 at 06:28 PM 0
Share

Unfortunately, that's only a local change that isn't represented by the settings. I also didn't find a way to set the Aspect Ratio from the code. As stated in the question, I would like to transfer exactly this setting to colleagues automatically.

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

126 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

Related Questions

What are the most common screen resolutions to have in my options menu 1 Answer

How to set screen resolution 1 Answer

Scale box collider to camera view? 2 Answers

Max screen resolution and delete the ones that are higher? 1 Answer

Ingame Quality Settings not recognized 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