- Home /
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: running the same code. left is build right is GameView how are these different then?
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.
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.
added image to show difference. both instances are the same code, but they are showing 2 different widths.
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?
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.
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
Follow this Question
Related Questions
Distribute terrain in zones 3 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