Is it possible to call Screen.SetResolution at startup?

When I try to call Screen.SetResolution() from either Start or Awake I’m getting some crazy display errors (or my machine freezes).

I am building for standalone on Mac (Snow Leopard).

Our game is getting rejected from the App Store because when the maximum resolution is chosen from the resolution dialog, the dock interferes with the game window.

We are trying to devise a solution that involves setting the resolution at startup, but are having some problems doing so.

We’ve already tried a couple approaches:

  1. Make the game start at 80% of the monitor’s maximum resolution
  2. Choose one of three pre-determined resolutions at startup based on user’s monitor size
  3. Make the game window slightly smaller if it is too close to the maximum resolution at startup

Unfortunately, all of these approaches involve manipulating the display resolution at startup. When we try to do this we either get a frozen computer or a game window full of nonsense.

Is it possible to call Screen.SetResolution at startup?

If not, does anybody have any thoughts on the best way to approach this?

We just disabled the resolution dialog and added a button that allows the user to change the resolution during the game. It only presents options that will not interfere with the dock (and fullscreen).

Update: we got approved (a week ago)

2 Answers

2

Hey,

I`am using

Screen.SetResolution(1024, 768, false) 

and this is working on both Mac & PC with no problem, but I found out when a ScreenCaptureSoftware like Fraps is running bevor I start the game, it is freezing or producing an error on Unity side.

I also tested this on a various range of Machines. XP, Vista, Win7, Mac SnowLeopard and on older PPC Mac´s with Tiger OS.

So I think the answer is yes, it is possible.

For point 1 & 2 you could create a var in PlayerPrefs for width and height, then using Screen.currentResolution.width(same for height) pass it to the PlayerPrefs var and then check them in an If statement like “if playerprefs.width is bigger than 1024 choose resolution xyz”

It is in an Awake function

I just tried again... using a very simple example. I added the most basic code possible to our Awake function: Screen.SetResolution(1024, 768, false) You can see the app start to load at the last resolution used... It pauses for a moment, tries to change resolution, and the result is a bunch of crazy modern art in the window. It's visually stunning, but looks nothing like our game! Actually, my computer freezes most of the time I try this.

That is really strange cause we use the same really simple code... I would check now three things: 1.the registry data of your project maybe there is something written that is causing the error. 2.Try it in Unity 3.3.0f4 -thats what I use 3.making a complete new unityproject to test it in a clear enviroment

Please take a loot at this post.
I posted a code that changes the resolution of the app that works fine in PC plataform.

http://forum.unity3d.com/threads/85157-change-game-s-resolution?p=1077840#post1077840

Hope it helps =)