PlayerPrefs.Set... vs. global variable

Hello,

What is the memory use (not storage space) on the use of PlayerPrefs.Set vs. a global variable?

The reason I’m asking is I’m going to be swapping scenes a lot and I was wondering which would be quicker to process.

At this time, I have a GetInfo() and SaveInfo() function that utilizes the PlayerPrefs.Get/Set.. However, I may have a lot of info to move around as the prototype grows in size. I might as well do what is easier/quicker for the processor now instead of rewriting a bunch of code.

Thanks,

-S

I would think nill. But with PlayerPrefs, you need to use Save() which can be a hit, if I am not mistaken. I think a global is a better bet. Also, with PlayerPrefs, you’ll have to get it as well. Not just one stroke with static.

If you just call it once and now (and not in every frame) and your PlayerPrefs has a small number of values (150 or less) it shouldn’t matter to much.

If you need to access it every frame or very often, then PlayerPrefs may kill your preformance, because every time you get or set a player prefs value the whole XML file will be loaded and parsed (or written in case of set), which is slow operation. That being said, there is several memory overhead from serializing/deserializing the xml

edit:
It’s best to write your own Options/Configuration class which can do at least a read cache and only write when the value has actually changed. Even better, write your complete configuration file using XML where you can cache all values, even the “set” ones and flush to disk periodically

You should only use PlayerPrefs if you specifically want the info to be persistent on disk.

–Eric