PlayerPrefs in the Update Method

    void Update()
    {
        //Give the PlayerPrefs some values to send over to the next Scene
        PlayerPrefs.SetString("Name", m_PlayerName);
    }

Source: Unity - Scripting API: PlayerPrefs.SetString

Why is the PlayerPref saved in the Update method? Wouldn’t that try to save every single frame? Isn’t it better to save one time after the player is finished entering their name?

1 Like

No idea, yes and yes!

1 Like

It is a bad example for sure. In the example’s OnGUI the value of m_PlayerName can potentially change every frame, so they are just writing it every frame instead of first checking if the value changed. They should probably just change the entire thing to no longer use the legacy UI at all, and instead use one of the current GUI’s events to just call SetString when the value actually changes.

1 Like

I will let the docs team know.

2 Likes

Just for completeness. You can rate pages of the documentation at the bottom of each page. Not sure if that is a good place for feedback or if it is actually read but it is an option. If you click ‘Report a problem…’ you can type more in-depth feedback.

1 Like

bro how’d you dark theme the docs?

Same way you can dark theme the forums. Browser extensions. This is the one I use for Firefox and chrome.
6778157--784172--upload_2021-1-29_0-45-19.png

1 Like