- Home /
Saving an Object of a Class
Hi, all! When I got well into the development of my game, I had to start over, because I re-discovered classes and such (I know, just bare with me).
So of course I restarted and switched to classes and development has been progressing smoothly and the elbow room and versatility that classes and class functions provide are fantastic.
My only problem here is writing a save / load function. I began writing it, and then realized that PlayerPrefs is still a viable, but extremely arduous, solution to this.
I am developing for WebPlayer. The things I need to save are purely Enums, booleans, ints, and floats.
No object position / game progress is saved. Simply the values of upgradeable things and such.
Can anyone inform me of a method other than PlayerPrefs (or if PlayerPrefs is what I need for this) that I can use for saving / loading data? I have easily over 100 variables I need to save.
(For instance, an object of an 'Upgradeable' class has the variables 'Value', 'level', and 'price', and there are 4 upgrades for each of the 8 guns 0_o
Am I using an incorrect method here?
Is PlayerPrefs what I should be using?
What other solutions are there?
Remeber - WEB development
Thank you for your time
Thanks! - YA
Answer by doug__ · Dec 04, 2012 at 02:42 AM
I wrote these dumb little classes as part of the github gamejam, maybe they'll be useful to you to look at:
Async browser communications class: https://github.com/onethousandfaces/game-off-2012/blob/master/Assets/utils.impl/n/Platform/db/impl/AsyncBrowserComms.cs
Uses local storage to store values in the browser (despite the name, it doesn't actually use cookies. :P): https://github.com/onethousandfaces/game-off-2012/blob/master/Assets/utils.impl/n/Platform/db/impl/CookieDbContainer.cs
You could also look at actually using cookies, but you'll hit a bit of trouble; the browser won't accept cookies if you're using a file:// url.
Player prefs isn't good for large amounts of info. The other solution would be to have a website backend to support your web game that lets you save data to it using HTTP requests; that's really the correct approach to take.
And what route do most single unity web developers take? I know more than just me have completed a game.
P.S I aim to have this game hosted by $$anonymous$$ongregate. I don't know if there are any perks to that like data hosting (?)
Oh and thank you for the scripts. I'll check the 'cookie' (not actually cookie) one out if I end up taking that route or if I don't. Either way, information is information! :D
Your answer
Follow this Question
Related Questions
Save and Load Questions 0 Answers
Null Reference Exception even after check 1 Answer
Create a terrain prefab? Saving a terrain? No? 1 Answer
nice Save but wrong load 0 Answers
Can't move after load saved game 0 Answers