Standalone player default window size?
I'm just learning Unity (after several failed attempts in the past).
Am going through the Unity tutorials, and got fixated on this issue:
When trying to build to a standalone exe/player, how do I set the default window size (for Windowed mode)?
I.e, 400 x 600 for a small, windowed game?
Here're the settings of my Player:
I tried searching the Unity forums, and the closest solution I found was to use Screen.SetResolution()
.
But whichever GameObject.Start()
I attach the script to will be executed too late.
ie, the Unity splash screen starts off at a huge window size, before shrinking to the size I want when my scene is finally loaded.
At the moment, this is still a trivial issue for me, albeit a rather irksome one.
Would appreciate some help and guidance.
Thanks!
Answer by joshualimm · Sep 30, 2017 at 02:31 PM
Ah, found it! Here's what's happening:
In the Player settings:
By default, both "Default Is Full Screen" and "Default is Native Resolution" are ticked.
Because I wanted a "windowed" game, I first unticked "Default Is Full Screen".
This causes:
The Default is Native Resolution to disappear
Default Screen Width/Height text boxes to appear
Turns out, I had to untick the "Default is Native Resolution" checkbox before the "Default is full screen". ie, before it disappears.
Since Unity hid the Native Resolution option after I unticked the full screen option, I thought it was not relevant for windowed mode. Turns out it was!
Answer by Horschty · Nov 08, 2017 at 01:48 PM
Are you sure? Unticking "default is native resolution" does nothing for me. I'm having the same problem and what I think is happening is that the settings are only the DEFAULT settings, when you start the program for the FIRST TIME. But once you started it at a size of 1600x900 and then change it in the player settings to 500x500 it just doesn't do anything anymore, since the actual window size has already been saved as 1600x900 SOMEWHERE. I don't know where but it definitely gets saved somehwhere, try checking "resizable window", rebuilding, resizing the window and reopening it. The window size has been memorized, but I have no idea in which file and how to clear the settings. So the only solution for me right now if I want to change the window size is to set "resizable window" to true, then starting the game, resizing the window with the mouse and closing it. But of course this way you can't set a specific size. Really really stupid if you want to change the window size after starting it for the first time, it's just not possible unless we somehow find out where unity stores the player settings and then clear them.
Edit: Deleting PlayerPrefs with PlayerPrefs.DeleteAll() seems to work even though I can't find any setting related to window size in the registry!?!
Same for me, but then I couldn't even get the right window size even while deleting player preferences. It seems like it went for the saved size from earlier runs anyway.
In the end I just set the windowed resolution programatically, and it works for what I'm making:
Screen.SetResolution(320, 480, false);
From my experience it really is the case that the settings under Resolution in PlayerSettings are just first-time defaults. If you want to change the default resolution for the subsequent game runs you need to do it from the Resolution Dialog which appears when the game starts. Set the resolution there, go to PlayerSettins and set Display Resolution Dialog to Disabled. From now on this dialog won't show up but the previously set resolution will stay.