Performance: PlayerPrefs for simple data
This affects the speed of saving and loading small pieces of data during gameplay or app usage.
PlayerPrefs.SetInt("HighScore", 12345); // No immediate Save call, rely on Unity auto-save
PlayerPrefs.SetString("PlayerName", largeJsonString);
PlayerPrefs.Save();| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Saving large JSON string with PlayerPrefs | N/A | N/A | Blocks main thread causing frame drops | [X] Bad |
| Saving small int or string with PlayerPrefs | N/A | N/A | Minimal impact, fast access | [OK] Good |
PlayerPrefs in Unity?SetInt with key and value.SetInt. Others use invalid method names.PlayerPrefs.SetString("playerName", "Alex");
string name = PlayerPrefs.GetString("playerName", "Unknown");
Debug.Log(name);PlayerPrefs.SetInt("level", 5);
int currentLevel = PlayerPrefs.GetInt("Level", 1);
Debug.Log(currentLevel);SetInt with key "highScore" and value 150, then call PlayerPrefs.Save() to ensure data is saved immediately.GetInt with key "highScore" and default 0 to load the saved score or 0 if not found.Pass the test and this pattern moves unknown