- Home /
Screen squashed/stretched after Android build
Hi guys. I am new to Unity and am currently working on a simple 2d platformer app with touch-buttons on a canvas. When I test the game through the unity remote on my Samsung J2 (which has a resolution of 960 x 540) the picture looks perfect:
However when I go to the build the game and I test it as an app everything in the scene is stretched and the buttons look way too big. I have experimented with many different resolutions and aspect ratios but every time the view is stretched, and the only difference being the different screen sizes and the buttons changing size.
I have also tried the app on 2 other android devices and on both the screen is stretched just the same.
For the above images i used an aspect ratio of 3:2 and my camera has a size of 5. In case you need it here is the info of my Canvas:
CANVAS
Render Mode: Screen Space - Overlay
CANVAS SCALER
UI Scale Mode: Scale with Screen Size
Reference Resolution: X=800 Y=400
Screen Match Mode: Match Width or Height (I have tried 0, 0.5 and 1)
Reference Pixels per Unit: 100
After looking at many other questions from other people and trying their ideas I have still not found an answer. Is there any settings I need to change or code I need to add? Any help gratefully appreciated.
Try setting your reference resolution to 80 x 40.. In my game I'm targeting 1920 x 1080 and when I have it as 1920 x 1080 stuff gets all wonky like text is huge but buttons aren't and stuff isn't in the right spot.. Setting it to 10x less of the value fixed it for me. Other than that I have my Screen $$anonymous$$atch $$anonymous$$ode to "Shrink" as well.
Also, Anchors maybe??
Not sure if the above solution will work for you but when I port to my Windows Phone (I know it's not android" my buttons and stuff look fine/have scaled properly.
Edit: ALSO! Check your "Player Settings" (Edit -> Project Settings -> Player) and mess with the supported aspect ratios and what not to find the best fit. The aspect ratio on your phone isn't going to match what you're intending exactly sometimes so this could also be causing the squashed/stretching. (I think this is the most likely area you'll need to look at for this)
Hi, i am also faced this type of issue but its solved now. I used this steps to make canvas fit at a set position, follow this steps- -In your canvas group create empty object and then set anchor points as per screen resolution of that empty group. - After that drag and drop all you assets from canvas to that empty group then child panel and attach aspect ratio fitter to panel as per shown in image.
I followed this steps and its working fine on all resolution devices. cheers...!
If you set the reference resolution to 800x400 you are telling unity that you layout is designed for a 2:1 aspect ratio. You should set it to values that matches the aspect ratio of real devices (most have 16:10, 16:9). Something like 1280x800 or 960x540 (and set the game view aspect ratio to 16:10 too to have a better control over your layout).
Answer by thealexguy1 · Jan 26, 2016 at 12:24 PM
Thanks for the help guys but I worked it out myself! All I did was attach this to my camera and it works perfectly!
void Start()
{
Screen.SetResolution ((int)Screen.width, (int)Screen.height, true);
}
Thanks again :)
Hey I'm trying this but I'm getting some errors with the void Start() line, any reason why it could be doing this?
Start a thread and tag us - Also please post the error you are getting @ShazBang
Answer by Anthonyknowles · Jan 25, 2016 at 09:35 AM
Hi you can try this script -make sure to attach it to your camera object
public class ControllingCameraAspectScript : MonoBehaviour
{
// Use this for initialization
void Start()
{
// set the desired aspect ratio (the values in this example are
// hard-coded for 16:9, but you could make them into public
// variables instead so you can set them at design time)
float targetaspect = 16.0f / 9.0f;
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width / (float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect / targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = GetComponent<Camera>();
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
else // add pillarbox
{
float scalewidth = 1.0f / scaleheight;
Rect rect = camera.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth) / 2.0f;
rect.y = 0;
camera.rect = rect;
}
}
}
Thanks for that script however the screen is still stretched. Is there any other settings I need to change aswell?
Also I want to point out that when the app first loads, for a split second the scene looks perfect. But then for the rest of the time it looks stretched.
Sorry bro, I didn't get notifications for this thread :( - yea I had the same problem and for some reason there was another conflicting script - I disabled one by one till it worked and then I re wrote the script I thought was causing it. worked after that 0_0.
Your answer
![](https://koobas.hobune.stream/wayback/20220612061614im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
canvas cannot show in android deveice 0 Answers
How to match a WorldSpace Canvas to Camera's viewport? 0 Answers
Detecting onDrag over UI images 1 Answer
How can i make my crosshair drag behind the camera? 0 Answers
Text smaller on Android 0 Answers