Is "Screen.SetResolution()" guaranteed to persist its changes on PlayerPrefs?

Can I assume that "Screen.SetResolution"is guaranteed to persist its changes on PlayerPrefs?

I’m working on my option menu and trying to figure out whether I should maanage and persist resolution and full screen settings on my own using PlayerPrefs.

Turns out, without doing anything, the change persists. I did some research on this and found out that there used to be something called “Display Resolution Dialog” and it managed the screen related settings through PlayerPrefs. I checked the registry for my game and found the same keys like “Screenmanager Resolution width”, etc.

So, apparently, I concluded that the “Screen.SetResolution()” saves its changes to PlayerPrefs as the “Display Resolution Dialog” did.

The thing is, I couldn’t find anywhere mentioning this officially. Can anyone clearly explain on this whether I can safely rely on this behaviour?

2 Likes

This depends on the target platform.

On Windows, Mac, Linux and Android, Unity remembers rendering resolution, full screen mode and whether it was rendering at native resolution (so for instance if you were rendering at 1080p on a 1080p display and then swapped to a 4k monitor, the game starts up at 4k resolution instead of 1080p).

On Windows, Mac and Linux starting with Unity 2021.2, it also remembers window position within the monitor (if running in windowed mode) and which monitor it was running on last.

Also, it’s not just Screen.SetResolution that saves these values. Anything that causes these parameters to change will update them.

3 Likes

It looks like changes to the quality level via QualitySettings.SetQualityLevel() are persisted as well (tested in 2022.1).

1 Like

Thank you. I’ve learned something new today. Can you tell me if Unity has similar functionality for saving items such as audio settings, post-processing configurations, anti-aliasing settings, and other preferences etc?

Saving at a lower resolution than the native one is saving fine, but attempting to save at a higher resolution than the native resolution will automatically revert the resolution to its native value. Unity 2021.3.29

I do not believe so.

Yes, we have logic to ignore saved resolution if it doesn’t fit in the connected display.

1 Like