Dimensions of object on mobile phones.

I have a 3D object that extends from -1 to +1 units on all the three axis and is centered at (0,0,0).I am building it for a game for Android devices. What will be its dimensions on mobile phones? Does that depend on on camera position as wwll? My cam is fixed at -10 on z axis facing the x-y plane. Will the dimensions of my object depend on the resolution of the screen? Can I get the dimensions the object is extended to using a function?

That depends on the camera’s position, the camera’s field of view and viewport, the mobile phone’s screen size and aspect ratio (although not the resolution of the screen). You can’t calculate this because the physical screen size is not available to Unity.

Well the object sizes will be the same on all devices in relation to the screen height. So if you have an object that is placed in front of the camera so it’s upper edge touches the top of the screen and it’s lower edge the bottom it will always touch the top and bottom of the screen, regardless of the actual screen resolution.

However the left and right edges of the screen depend on the screen’s aspect ratio. So if your screen is wider than your original setup you will see more in the x and -x direction. If the screen width is smaller than your original width things might get cut off.

Unity’s projection matrix of the camera will always keep the aspect ratio so objects will keep their aspect ratio (a square looks like a square and not like a rectangle. i.e. stretched or clinched along the x axis).

So for example on a mobile phone, if you allow rotation of the screen, you can get very different aspect ratios depending on the screens orientation. Here are some examples:

This is our development resolution: 600x1024 (WSVGA Portrait) the aspect ratio Unity calculates is “0.5851648” and the scene looks like this:
600x1024 WSVGA Portrait

However if you switch to Landscape: 1024x600 (WSVGA Landscape) the aspect ratio is “1.706044” and the scene looks like this:
1024x600 WSVGA Landscape

As you can see the height has been adapted to the new height. So object position / scales will keep their relations to the screen height. However the screen width is now much bigger so we see alot more on the left and right. Of course if you originally developed in Landscape everything at the sides will be cut off in Portrait mode.

The next problem is, that there are different screen resolutions out there and even is you only use Portrait mode most have slightly different aspect ratios. Example: The same scene viewed in 320x480 (HVGA Portrait) (calculated aspect ratio: 0.6675824):
320x480 HVGA Portrait

As you can see there is a little bit more space at the sides since the aspect ratio of this resolution is slightly larger than the original one.

You can set the aspect ratio manually (which disables the automatic calculation) by setting camera.aspect manually to your desired value. Just for completeness: You have to call ResetAspect() on the camera in order to have it again calulated automatically by Unity based on the screen viewport.

If you would for example use the aspect ratio of our original resolution (0.5851648) for any other resolution, the result will stretch accordingly. Just like you take the original image and strech it to fit the new resolution. For small variations you almost don’t notice the stretching but it will still be noticable. For larger differences in the aspect ratio you can see heavy streching. Here are the same example as above, but with the manually set aspect ratio of “0.5851648”:
320x480 HVGA Portrait old aspect ratio 1024x600 WSVGA Landscape old aspect ratio

Keep in mind that everything will be streched that way. Even text which might look strange if the streching it too much.

Finally here’s an example the other way round. Here we setup a scene in landscape mode and show how it looks like when viewed in protrait with a manually set aspect ratio and with the normally automatically calculated aspect ratio:
aspect change