Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Easiest way to save a List variable to PlayerPrefs in Unity

Posted on March 13, 2021March 13, 2021 by Habibie

Using PlayerPrefs in Unity is very useful to save and load user/player’s game data.

But, problem is our player data is not always as simple as single string, or integer or float value of variable.

For example, how do we store a List to PlayerPrefs?

My favorite way to do it is to convert the List to a single line of string with comma separator.

string datastring = string.Join(",", yourListHere);

Now your datastring contains a comma separated items such as “bag,toothpaste,chair,blabla”

Then you can save that string to PlayerPrefs like this:

PlayerPrefs.SetString("CollectedItems", datastring);

Then you can simply retrieve it by calling PlayerPrefs.GetString…

string datastring = PlayerPrefs.GetString("CollectedItems");

And how to convert the comma separated string to our original List? Take a look at this example:

yourListHere = datastring.Split(',').ToList();

But you need to use System.Linq for this last line.

Post Views: 288
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme