Applying graphical settings at start

Hey, i would love to know how you do graphical settings and why.

When i start a game, i want to apply the settings the user configured when running the game last time. Setting, saving, all clear. Loading a few config lines is rather simple as well.

So when do you apply the loaded graphical settings? I guess it should be done before loading assets, so a dead dark scene without a camera and just a script that changes resolution + quality and then load the main menu?

How do you do that, and why?

You can use this attribute

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

1 Like

Nice, i didnt know that. Thanks!

Or having initial scene, which load configs files, then call another scene, which loads other parts of the game.
Many ways to do so.

You also may want to consider situation, if changing graphics setting can be executed, without restarting the game.

1 Like

How would i even do that? The project settings determine the start values, like “use native resolution and quality medium” and then i can override that with my own scripts, but is there a way to have unity start with certain settings?

For example quality settings?
You can do that via scripting, in QualitySettings API.

1 Like

@Antypodish Okay, i phrased that badly. I know how to change quality settings and resolution when the game is running. The game starts and then i can change settings to whatever the config file says. The question is: If there are options that require a restart ( i don’t know yet if there are, but you wrote that i may want to consider that ), which implies that its not enough to change it in game, how do i make the unity engine start next time with those settings?

You need test this for your specific use case, ensuring all functions as expected.
If not, then player may need to restart application.

Using for example PlayerPrefs
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

You can also store configs data in text file an load with JSON or any other way.

1 Like

I understand. But PlayerPrefs is something that i write and read and it’s my job to apply settings saved in there via script.

So example:

  • Player starts game.

  • Setting has a standard value of A.

  • Player changes it to B.

  • My Script saves B into PlayerPrefs.

  • Player ends game.

  • Player starts game.

  • Setting has a standard value of A.

  • My Script automatically reads setting from PlayerPrefs and applies B to setting.

I think this is the standard way of applying setting.

So, if there is a setting that requires a restart, which means it can not be applied while running the game, how can this way of loading settings via PlayerPrefs work, because it is done while running the game? If i apply settings with a RuntimeInitializeOnLoadMethod-attributed method at start, like even before the Splashscreen, so before assets are loaded, is that early enough? I do understand that there are settings that apply to the way scenes and gameplay is initialized, so applying that first makes total sense.

This however,…

…implies that there are things that require a restart of the engine. I know i am very pendantic right now and i may interpret more into that than you intended.

I’m also really grateful that you take the time to help me understand things.

Just do it. Beats waiting to find someone who happens to report back to you here.

2 Likes

Everything in QualitySettings with a public setter should be fine to change at runtime. I never ran into a problem doing this. If something needs a reload after changing a setting, Unity will do this automatically in the background. So applying all settings in an empty scene before loading the actual game should work just fine.

The same thing applies to the scriptable render pipelines. Changing any settings in the render pipeline assets at runtime shouldn’t cause any issues. Maybe it lags for a moment directly after changing specific settings, but that’s still way better than restarting the game after a change.

The only thing I know of that needs a restart is the rendering API, but you usually don’t let the user change that in the game settings anyway. Simply let Unity select the best available API for the current platform automatically, or specify your own API order in the player settings.

2 Likes

@ippdev @Armynator Alright. Thanks!