As I stated I can't find a working answer anywhere else. I have a game where you are to draw out your own weapon and I'm storing that information in an array. How?


You would first need to serialize your array into a string. One way to do this, is to create a tokenizable string representation of your array data.

For example:

string data = "";

for (int n = 0; n < Array.GetLength(0); n++) {
    data += Array[n].ToString();
    if(n != Array.GetLength(0) - 1)
        data += ",";

PlayerPrefs.SetString("ArrayData", data);

Then loading this back into the array would look something like this:

string data = PlayerPrefs.GetString("ArrayData");
string[] tokens = data.Split(',');

Array = new Array[tokens.GetLength(0)];
for (int n = 0; n < tokens.GetLength(0); n++) {
    Array[n] = tokens[n];    //Cast to var type here
| improve this answer | |
  • \$\begingroup\$ Is there no join operator or method? \$\endgroup\$ – simbabque Jan 18 '17 at 17:48
  • \$\begingroup\$ It isn't working at all! I'm getting errors on inserting semicolons \$\endgroup\$ – The Mattbat999 Jan 19 '17 at 23:12
  • \$\begingroup\$ What is the error. \$\endgroup\$ – jgallant Jan 19 '17 at 23:15
  • \$\begingroup\$ On the line that says. string[] tokens = data.Split(','); the console displays " ';' expected. Insert a semicolon at the end." On colomn 15 and 17 \$\endgroup\$ – The Mattbat999 Jan 19 '17 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.