Localization Playerprefs remember language on startup
What would be the best way to have Unity remember a language choice even if you close and re open the game? I have multiple languages using the Unity official Localization tutorial but I need it to remember what language as the language screen isn't the first screen you see when opening the game (I have it default to English for starters but have a language scene which reverts back to the start screen with the chosen language). Thoughts?
I was thinking playerprefs using setstring somehow but how would you do the whole getstring at game launch and remember a previous choice in a previous session?
Answer by Erdal42 · Jun 15, 2020 at 12:11 PM
I have this exact setup working. It is pretty straightforward once you get the startup selection.
Under Project Settings > Localization > Locale Selectors , add a Player Prefs selector.
Either use the default given key for your Player Pref "selected-locale" or change it here. The value that you will save is the locale's code or parent code (ie. fr-FR or fr etc.)
Configure everything according to your project, don't forget that the order of the selectors is very important. In my case I have:
Basically, the game checks if any command line locale is given (the most prioritized), if not (or given but locale not found), then it tried player pref, then (for example Player Pref not yet set in-game) it tries the system one, and finally falls backs the the specified (here English).
Cheers!
Your answer
Follow this Question
Related Questions
What is proper character set for Japanese players that using in game chat? 0 Answers
how to convert a dynamic playerpref to a dynamic int variable? 0 Answers
[DIY] Need some help supporting localization on a game and updating UI when a language is selected 1 Answer
How to prevent to save or send a big json string? 0 Answers
How to get the active/loaded Scene then turn the name of it into a string? [C#] 1 Answer