Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by gardian06 · Jul 29, 2013 at 05:58 PM · buildresolutiongameview

resolution differences between GameView, and build

in my game I am setting my GUI to display to the screen so that resolution does not matter. I have done all of my initial setup work based on 800X600, but instead of just constants I am first setting universal constants based on resolution, and then just doing math based on that. for example:

 void OnGUI(){
     float width = Screen.width/8; float height = Screen.height/6;
     float wSpace = width/10; float hSpace = height/10;
     GUI.Box(new Rect(width*2+wSpace*2, height+hSpace*2, width*2+wSpace*2, height),
         "welcom here is some text that will" + '\n' 
         + "show up @800X600 in the GameView," + '\n'
         + "but in a build it will be clipped off," + '\n'
         + "and the window will be pinched");
 }

this way I can just run through and set all of my Rects based on multiples/addition/subtraction, of these instead of calculating hard numbers for each thing, and then when the resolution changes having nothing work right.

this all works perfectly in Editor/GameView, but when I do a build, and open the build at the target resolution nothing matches what I had set.

  • text boxes are pitched

  • buttons don't line up

  • things are clipping through boxes, groups, and screen boundries

I can maybe see instances why at lower resolutions these calculations don't particularly work, but why at the target resolution that I am checking against is it inconsistent between Editor/GameView, and Build?

Edit corrected incorrectly copied division of contants

adding picture:alt text running the same code. left is build right is GameView how are these different then?

res.png (56.8 kB)
Comment
Add comment · Show 6
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 VolureDarkAngel · Jul 29, 2013 at 06:46 PM 1
Share

This post does not give enough information for a response. You should include some of the code that uses these variables and is showing up wrong, otherwise you will continue to be skipped over.

avatar image gardian06 · Jul 29, 2013 at 07:23 PM 0
Share

edited code to give example

avatar image VolureDarkAngel · Jul 29, 2013 at 07:45 PM 0
Share

Unfortunately I was unable to produce the results you are getting. I run the game in unity as well as in standalone form and I get the exact same results either way.

avatar image gardian06 · Jul 29, 2013 at 08:12 PM 0
Share

added image to show difference. both instances are the same code, but they are showing 2 different widths.

avatar image Jamora · Jul 30, 2013 at 04:23 AM 0
Share

What resolution does it say in the Stats, next to $$anonymous$$aximize on Play in your game view? Because what it seems like is that you're designing for a larger resolution. I tested your code and it does the same clipping behavior on both Game view and Build @800x600.

I also noticed the font is bigger in the build. $$anonymous$$aybe an OS thing?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Jamora · Jul 29, 2013 at 07:10 PM

The only way I've found out to make any UnityGUI bend to my will is by using percentages. That way you don't have to care about resolutions; if something is 10% (of the Screen width) off the left edge of the screen, it'll be 10% no matter the resolution.

The way I achieve this is have a bunch of global Rects, one for each gui element and make a method for calculating all positions for the Rects, which is called on a resolution change.

     void OnGUI(){
         CheckResolutionChange();
         
         GUI.Button(startGameButtonRect,"Start!");
     }
     
     void CheckResolutionChange(){
         if(oldWidth != Screen.width || oldHeight != Screen.height){
             CalculateRects();
             oldWidth = Screen.width;
             oldHeigh = Screen.height;
         }        
     }
     
     void CalculateRects(){
         startGameButtonRect = new Rect(
             Screen.width*0.1f /*10%*/, 
             Screen.height*.5f-Screen.height*.1f /*centered, as button height == 20%*/, 
             Screen.width*.2f,
             Screen.height*.2f);
     }

EDIT: I had this issue both in the game view and the build, using the code you provided. After some playing around, I made my own guiskin and set the font for the default box (which you are using) as 12pt Arial. This seems to have fixed the issue.

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 VolureDarkAngel · Jul 29, 2013 at 07:47 PM 0
Share

This is similar to what I use.

avatar image gardian06 · Jul 29, 2013 at 08:19 PM 0
Share

I should be achieving the same goal I just have to do complex division once a frame, and don't have to have a whole bunch of Rects sitting around if I need like 20 static things in different positions on the screen.

I will take the hit on division once a frame, but these should achieve the same goal. I just divide by 8, and 6 ins$$anonymous$$d of 10.

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

17 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

Related Questions

Distribute terrain in zones 3 Answers

Is there a way to change the window resolution of a build without having the window snapping to the center of the screen in window mode? 0 Answers

Game window is broken 3 Answers

Unity 2018 Build to 4K Screen high resolution performance 0 Answers

Add and Select Game View Resolution Programatically 5 Answers


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