Is it appropriate to have PlayerPref IDs the same as variable names?
Is it appropriate to have PlayerPrefs ID's the same as variable names? Are there any reasons why I should not do this? Would problems arise in the future?
For an example look at the code below.
public class BoxSize : MonoBehaviour {
public int width = PlayerPrefs.SetInt ("width", 100);
public int height= PlayerPrefs.SetInt ("height", 100);
public int length= PlayerPrefs.SetInt ("length", 100);
}
You should initialize your variables inside the Awake function ins$$anonymous$$d of when you declare it.
Then, you should be more specific in the keys of the PlayerPrefs since you might have duplications in the future. Thus, choosing "BoxSize.width" will be a better idea than just "width"
Thank you Hellium. This cleared the confusion I had about PlayerPrefs and na$$anonymous$$g conventions.
Really using PlayerPrefs isn't always a great idea as for windows its stored in the Registry. I would point you towards a file based solution, check out a video made by the Unity live training $$anonymous$$m about the topic: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading
Your answer
![](https://koobas.hobune.stream/wayback/20220612072656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Change from mouse click to free space to a canvas button 0 Answers
save variable from previous scene 2 Answers
Game working in pc but not in Android While Testing 0 Answers
Is it better to split a script into different scripts? 1 Answer
How to use a dependency injection mechanism between scenes 1 Answer