in unity

Unity: Get Game View Resolution

Get Game View Resolution Unity

The game that I’m currently developing should switch spritesheets for different device sizes.

I have 3 of them:
SD for iPhone 3GS
HD for iPhone 4(S), iPhone 5(S,C) and iPad 1 (non-retina)
UD (Ultra HD) for iPad’s with retina.

And I have a script that switches between them by detecting current device resolution.


Everything works well when I test on device, but when I test from Unity editor the Screen class always returns resolution of my desktop display (1920×1080), no matter which value I set in the GameView.

Get Game View Resolution in Unity Editor

As you can see on the screenshot, I’ve set my resolution to iPhone 3Gs (480×320) and would like to get that resolution (480 x 320) in the code, so that I could test loading and switching between spritesheets.


Good news that we can use Reflection to get this value. And here is a code to do this:

The code to take the game view I found in this answer.

This way we can set the resolution we want to test in in the Unity Editor (e.g. 960×480 to make the code load iPhone 4 resources) and test that the code picks correct resources and adjusts everything just as if it was running on device with target resolution.

Hope this helps someone.

Write a Comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Great Solution! It helps me a lot to test Bundle download and screen size on my project! Thank you!