How do I set an Android applications resolution?

How do I set the resolution for a Unity Android application?

4 Answers

4

You can set the resolution of your application by calling Screen.SetResolution which is documented here:

http://unity3d.com/support/documentation/ScriptReference/Screen.SetResolution.html

If you add this to a scripts start function and attach it to the Main Camera this will force the application to display full screen at a given resolution.

Here is what worked for me and although I am still learning Unity, this seems convenient:

I have set up my scene using canvas as per this tutorial:


Then select Canvas in Hierarchy (instead of camera), then in the Inspector:

  1. Canvas > Render Mode > Screen space - Overlay
  2. Canvas Scaler (Script) > Ui Scale Mode > Scale with screen size
  3. Canvas Scaler (Script) > Reference Resolution > e.g. 800 x 600 (or whatever size works for you best)

I hope this helps somebody.

Void OnGUI()
{
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1.0f * Screen.width / 1024, 1.0f * Screen.height / 768, 1));
.
.
.
.
}

There is also DPI and resolution scaling to consider, as detailed here:

and here:

I haven’t quite figured it out yet, but those affect whether the device attempts to render to every pixel available (eg: every pixel availabe in a 4K screen) or scales up a lower-resolution buffer to the final screen output (eg: rendered to 1920x1080 then scaled to the screen display).