- Home /
PlayerPrefs in web player are not the same
According to the script reference, "There is one preference file per Web player URL and the file size is limited to 1 megabyte." I understood this to mean that there was one file on the server. I think it should actually say "There is one preference file per Web player URL on each client and the file size is limited to 1 megabyte." I think I just wasted a whole bunch of time on something I can't use. The playerprefs are doing exactly what I want them to, but use a different dataset on every machine that accesses the page. That is completely useless for my project.
Is there a way to save playerprefs on the server, so that I can have a usable login and high score system that is the same for all users? If not, how can I accomplish that without learning three new languages to use a real SQL database? I can get things to work in C#, but I don't know or have time to learn all the SQL, Java, and/or PHP it appears I would need.
Answer by Coderdood · Jun 08, 2013 at 04:57 AM
Question 1
Is there a way to save playerprefs on the server, so that I can have a usable login and high score system that is the same for all users?
No. You can think of a Unity webplayer game as just being data that is downloaded by each player and instead of being installed and played as a standalone exe runs in the web browser.
Question 2
If not, how can I accomplish that without learning three new languages to use a real SQL database? I can get things to work in C#, but I don't know or have time to learn all the SQL, Java, and/or PHP it appears I would need.
No matter what route you take you are going to have learn something new to do this. You don't have to learn SQL, Java, and PHP but you -will- have to learn something.
If you don't care about a usable login system then you can probably get it done without learning too much more just by searching for high score systems on google. There is even an example here.
A usable login system is -definitely- going to take real database / web development skills though, especially if you want any sort of security. As its a very complicated subject to make a good login system you might seek help at a more generic resource like stack exchange where some web development specialists might be found.
I was able to get what I needed, for now, with the PlayerPref, but (see above). Security is not a big issue at this point. The central, persistent data storage is my biggest concern for now, but if the project continues (the right people like what they see) it will need a real SQL database.
I have a good SQL reference (text book) that I think I can get what little I need done. I'm not so concerned about that end. $$anonymous$$y problem is that I have never been able to get the one thing (Unity or VS C#) to talk to the other (SQL database). All the documentation I've found has involved a bunch of middle-ground (PHP, CGI, whatever) that I'm completely clueless about.
If I could just get my foot in the door, making Unity C# give direct SQL commands to the server, I think I could scratch, claw, stand, walk, then run with it. I just can't seem to find that key part.
As explained in this answer - and I attempted, poorly, to explain above:
"Unity works just like Java/Flash or any other browser plugin in this regard. It is run on the client machine - not the server and can therefore only physically have access to the client file system. $$anonymous$$ost plugins (including the Unity plugin) restricts this access though - to prevent malicious content from accessing private user data or wreaking havoc on the drives of unsuspecting web surfers. So you have direct access to neither."
The Unity web player never executes code on the server - so to your application the server does not exist and there is no way to do anything on the server without writing code outside of Unity.
This includes persistent data storage on the server.
Your answer
Follow this Question
Related Questions
I am having trouble getting a web build to save out an .upp file from my code 0 Answers
How To Add PlayerPrefs Scores? 1 Answer
Number of played games 1 Answer
Get PlayerPrefs file path directly at runtime? 0 Answers
I can't save my money? :< 1 Answer