Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebPlayer Player Prefs/Alternative to Player Prefs

Discussion in 'Scripting' started by AllanMSmith, Jan 23, 2015.

  1. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Hi,

    I'm developing a game using Player Prefs to store everything I need to, its not a whole lot of stuff and the Player Prefs file hardly gets bigger than 10 kb. I've been developing it and testing on my web server and never had problems with it, works perfectly.

    However, my client just published the game on his server and it is no longer working when using a windows machine (its working on a mac). Tried using all browsers, Windows 7, 8 and 8.1, and what happens is that it creates a folder at %APPDATA%\Unity\WebPlayerPrefs, but does not create the .upp file it uses.

    The game was working on my server, and the exact same build does not work on another, not on windows machines... any idea of what might be causing this?

    PS: My client has a gaming portal with other Unity games, which use player prefs (and the file gets created).

    If not, could someone at least point me to another possible solution for a webplayer game to save persistent data, preferably in a similar way, maybe with a XML or whatever, not with a database?

    Thanks very much for the attention,
    Best regards,
    Allan
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Kiwasi likes this.
  3. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Hey Graham,

    Sorry for the delay, since I am depending on the client to upload the game I don't have much control about it =/

    But, I've placed the following code:

    Code (CSharp):
    1. try
    2.             {
    3.                 PlayerPrefs.SetInt("testeint", index);
    4.             }
    5.             catch (PlayerPrefsException error)
    6.             {
    7.                 myTextMesh.text += error.Message + " Failed on Index " + index.ToString() + ".";
    8.             }
    9.             yield return new WaitForSeconds(1);
    10.             try
    11.             {
    12.                 PlayerPrefs.Save();
    13.             }
    14.             catch (PlayerPrefsException error)
    15.             {
    16.                 myTextMesh.text += error.Message + " Failed on Save.";
    17.             }
    And got nothing... apparently there are no exceptions, it just doesn't work =/ I tried using Unity 4.5.5f1 and 4.6.1, generating the build both from a Windows 8.1 and Mac OS X machine... no change. Any ideas?
     
  4. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Hey, just an update, I've created a project with nothing else but this code:

    Code (CSharp):
    1.     private void Awake()
    2.     {
    3.         if (PlayerPrefs.GetInt("rodou", 0) == 0)
    4.             mesh.text = "Nothing saved";
    5.         else
    6.             mesh.text = "Value has been saved";
    7.         PlayerPrefs.SetInt("rodou", 1);
    8.         PlayerPrefs.Save();
    9.     }
    I enter the page, it displays "Nothing Saved". I refresh the page, it should say "Value has been saved", and it does when the file is hosted on my server, however it shows "Nothing Saved" all the time on my client's server. Is there some kind of configuration required for the PlayerPrefs to work correctly on the server?

    Thanks!
     
  5. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Awake() might be too early. What happens if you move that into Start()?
     
  6. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    I will make the test and let you know of the results, but should take a while since I need to wait for my client to upload the file.

    However, on my original project, I was calling "PlayerPrefs.Save()" in many moments throughout the gameplay, not only Awake, so I would guess it would get created anyway?

    I will post again asap with results.

    Thanks for the attention,
    Cya
     
  7. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Ok, finally managed to test it with the call on Start, no change =/
     
  8. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Now tested with versions 4.1.5f1, 4.2.2f1, 4.5.5f1, 4.6.1f1... still the same... isnt there something that oculd be wrong on the server??
     
  9. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Is there anything written to the playerprefs location? Anything weird written into the Player.log? Does your client have some restricted file access? What browsers are used?
     
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Is it plausible this is a sand boxing / security issue? Some of the games I've launched have had trouble accessing browser functions. No real clues, just throwing it out there.

    One obvious solution wod be to move the saved game to a server. There are some pretty decent third party ones out there.
     
  11. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Nothing gets written to the player prefs location, no file is created, but the folder named after the server address is created. Im not sure how my client's server is configured, but Im not sure what to ask either. But, it is a gaming portal, with other unity games on it, and their player prefs work, so Im not sure exactly WHAT could be causing this trouble. I tried it on Chrome, Firefox and Internet Explorer, all yielding the same results.

    I'm not really sure, but I would guess so. But how could I move the saved game to a server? I mean, webplayer dont have access to file creation, not even the .upp is getting created, or do you mean a server like a database of sorts?

    Thanks for the support so far guys
     
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I've used parse for online saved games. Not sure how well it fits with your client model, but it worked for me.
     
  13. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    So, I just got an e-mail from my client saying that he managed to host the game on a static page (its a big company, getting this kind of stuff done is not very easy), and now it is working properly. However, I would say that guys from Unity need to check out what could cause this kind of problem, even if it is some kind of server-side configuration... this caught us totally off guard and costed many days of work looking for solutions (and finding none).

    Anyway, thanks again for the support, I believe we will go with the static page for now, but if you need any more information from me that could help with this issue, please let me know.

    Thanks!
     
  14. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Well, if you think it's a Unity bug, then please submit a bug report with enough data to allow someone from QA to investigate. (If they hit the link, and it all just works, then they'll close the case as not reproducible.) So you'll want to try hard to avoid that.
     
  15. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    I dont really think it is a Unity bug, but there is some kind of server side configuration that could have been causing the error. Even if that is the case, wouldnt it be worth it for Unity's documentation to mention the pre requisites of a server hosting a webplayer game?

    Anyway, I can't make sure the bug will endure until they check the bug report since the problem was not on my server, but I had sent a bug report a couple days ago, hopefully they get to see it in time.

    Again, thanks for the help!
    Cya!
     
  16. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    If you can help us understand what the problem is, then of course I'll get that into the docs to help everyone. It's just I think learning what the problem is is quite hard. :-(
     
  17. AllanMSmith

    AllanMSmith

    Joined:
    Oct 2, 2012
    Posts:
    180
    Graham, I sent you and inbox about this issue so we might find a way to help you.

    Thanks!