So, I'm porting a game to the Android for the first time in Unity3D. And I've run in to a few problems along the way. My current problem is the resolution doesn't seem to be right, it cuts off the edges of the screen and my scrolling stops for scrolling the screen left/right are no longer in the right place.

After doing a bit of research, a lot of people say you need to make your game Resolution Independent to be able to run on all Androids/Iphone/Ipad. Is this true? If so, how do I go about doing that? If not, how can I help fix the resolution so when I port to mobile devices it looks right?

EDIT: I still don't really have what I need, resolutions still aren't working properly even with the code and tricks listed below. I need some way for the resolution to adjust based on the device. For some reason when I try to retrieve the resolution of a device using Mungoid's code it returns 0x0

  • 1
    \$\begingroup\$ You'll need to go through any bit of code that assumes a certain screen resolution and change it so it can take the current screen resolution and does something with it. Depending on what you're doing and how, there is no one-size-fits-all solution. \$\endgroup\$
    – Tetrad
    Commented Apr 25, 2012 at 20:33
  • \$\begingroup\$ As far as specifics, this question goes into some detail (there are a lot of questions about this on the site) gamedev.stackexchange.com/questions/51/… \$\endgroup\$
    – Tetrad
    Commented Apr 25, 2012 at 20:54
  • \$\begingroup\$ Ahh, so basically what Namar said: "Make sure you place everything with ratios. For example a health bar would be placed at 80% of the screen width with 10% of the screen width for its horizontal scale" so how could I fix referencing specific areas in space? My screen scrolling goes based off of specific areas in world space, but that seems to get messed up with the resolution changes. \$\endgroup\$ Commented Apr 25, 2012 at 22:27
  • \$\begingroup\$ Could you be more specific about your problem? You say the resolution "doesn't seem to be right" and it is "still off" - but screen resolution is usually a fixed property of the device. So it's not the resolution that is wrong, but the way you render to the screen. If you make assumptions about how wide and high the screen is, you will always have trouble on different devices and aspect ratios. \$\endgroup\$
    – Kylotan
    Commented May 9, 2012 at 18:22
  • \$\begingroup\$ I guess really what I'm trying to do is write a code to find the lowest resolution, set the game to that, and scale all the objects accordingly. I know how to set the scale of the playfield, but I can't seem to get the resolution of the device. therefore the game is "too zoomed in", or everything's too big. \$\endgroup\$ Commented May 9, 2012 at 22:24

2 Answers 2


A problem you'll run into with Android is that every different device has its own screen size, resolution, and pixel density. If you want your game to look identical on all devices, you're in for a lot of work and will probably never be pleased with the results. Either the game will appear stretched on widescreen displays or compressed on non-widescreen ones. I suggest you decide what's truly important and let anything else slide a little.

Without any screenshots or knowledge of what your game is and what it looks like, we can all speculate solutions but we don't have specific direction to give you specific counsel.

In Unity, you can access the dimensions of the current screen with the Screen class: Screen.width and Screen.height (among other properties). You could then change the Camera's aspect ratio to change what is visible on your different sized screens based on the screen dimensions and your personal expectation of what should be visible.

If you need to ensure any HUD displays are scaled properly, you can do that by changing the GUI transform matrix based on the screen's dimensions in every OnGUI() function. I've done it before by making this simple script and attaching it to anything that rendered GUI elements I wanted scaled:

//GUI values in code are assigned based on an 800x600 screen
private var nativeWidth : float = 800.0f;  
private var nativeHeight : float = 600.0f;
private var guiMatrix : Matrix4x4;

function Start () 
    var scale : Vector3 = Vector3(Screen.width / nativeWidth, 
                                  Screen.height / nativeHeight,
    guiMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);

function GetGUIMatrix() : Matrix4x4
    return guiMatrix;

Then, in the actual OnGUI() function(s), I set the transform matrix right away:

function OnGUI()
    GUI.matrix = guiScale.GetGUIMatrix();
    /* Everything Else */
  • \$\begingroup\$ Setting the aspect ratio of the camera based on the screen width and height doesn't help, when the phone is vertical it doesn't show at all and when the phone is horizontal it shows exactly the same as before. The game is split up in to three sections, you smoothely scroll between sections with your finger (Like in Angry Birds), here's a picture of what the left side is supposed to look like. And the middle. Here's the left side when my phone is held vertically, \$\endgroup\$ Commented May 10, 2012 at 19:43
  • \$\begingroup\$ And here's horizontally. Hopefully these pictures can help, this is my first time porting from Unity to Android, or even making an Android game. I'm a bit lost. \$\endgroup\$ Commented May 10, 2012 at 19:44
  • \$\begingroup\$ Judging by (my interpretation of) your explanations and your pictures, the problem isn't resolution; your camera isn't in a location that can possibly show everything you want on a small screen. Make your levels smaller or move your camera back to show more or something. I'd suggest setting your game window to a much smaller size to represent the size an actual device instead of the 1230x530ish size you have now so you can get a feel for what you'll see when you push it over. \$\endgroup\$ Commented May 10, 2012 at 22:51
  • \$\begingroup\$ The problem is I've already zoomed out the camera quite substantially. If this problem will be persistent, how can I accurately account for various screens and sizes and modify to that? \$\endgroup\$ Commented May 13, 2012 at 19:11
  • \$\begingroup\$ @TimothyWilliams, you could probably work something out by picking a minimal resolution (800x600 or something) that your game works with. Then, use Screen.width and .height in tandem with Camera.fieldOfView and Camera.aspect to reproduce the same view on arbitrary screen sizes. It would just require some trig to work out specifically how to do it. \$\endgroup\$ Commented May 15, 2012 at 16:22

you could try something like the following and apply it. I would guess that a mobile device should only return one resolution.

function Start()
    var resolutions : Resolution[] = Screen.resolutions;
    // Print the resolutions
    for (var res in resolutions) {
        print(res.width + "x" + res.height);
    // Switch to the lowest supported fullscreen resolution
    Screen.SetResolution (resolutions[0].width, resolutions[0].height, true);

Also take a look here for more info about the Screen in unity http://unity3d.com/support/documentation/ScriptReference/Screen.html

  • \$\begingroup\$ This didn't help me, the resolution is still off. \$\endgroup\$ Commented May 7, 2012 at 17:11
  • \$\begingroup\$ It returns "0x0" on my Android for some reason... \$\endgroup\$ Commented May 7, 2012 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .