I’ve been doing some research and finally thinking that I should piece my game together a bit more, so I can actually test it officially. However, I was looking into saving and loading, read some threads around here for the past couple of days, and am quite confused. I know there are PlayerPrefs, there is the Unity Serializer Wizard (which may or may not be the Serializer I’ve heard in another thread nearby), and there are assets on the store.
This is as far as I know:
PlayerPrefs: Simplistic and relatively easy to use. However - I’m not sure why - this isn’t good for lots of different, particularly dynamic data. And also this doesn’t work well (if at all) for mid-game saving and loading
Serializer: Saves a ton of data, works mid-game, seems alright (at least for the Wizard). However - at least for the Wizard - this doesn’t seem that flexible, and for more simple things, I’m not sure if I should use it
Asset Store: Least flexible, probably costs money, rather wish to do this myself honestly
At the moment, I’m working on a mobile game. However, I intend to a) have screen wipes/splash screens between (re)loading and such, b) save scores instantly once the level is done and the score/end screen is shown (and of course compare values to see if this is a higher score as a tiny niche feature), and c) have little easter eggs as well as requirements from previous levels that unlock things (you collect these special items, you unlock the “secret” stage).
What would be the best thing to choose? My game in development isn’t that complex actually, but I rather not work hard on menus when I would have to reprogram them all to a point - alongside the beginning and end of each level - after using one method but finding it incompatible with what I want.
Also, I’d appreciate links and examples, Really appreciate
Thanks for even reading through this whole blocky post!
Dynamic data can be added to list, and that list be saved to one player Pref, then loaded to fill the list again. You can cover a lot of ground that way.
I like saving to .txt using StreamWriter, but my most favorite save system is Sqlite3. Its fast and clean with just one .dll.
Hmm… Guess I’ll start to really look into PlayerPrefs, although I don’t know why one person commented why this couldn’t be used mid-game.
What if I needed to dynamically save and load a level mid-game, including enemies, player, and other dynamic objects? I don’t see myself every using this on mobile platforms, so I guess all options are open.
Although I probably have no idea what I’m talking about (yet), but would each list be per level, or should I get creative and make each entry as a level (separated by commas or such to essentially create a 2D array)?
Also, is saving to .txt or .dll a good idea for mobiles? (or, for .txt, anything as the player can edit the data easily, I’m guessing?)
Hello MDragon - Both .txt docs and db files can be encrypted or hidden as far as I know lol. I keep hearing that nothing is secure if a hacker want’s it bad enough.
Dynamic saving - When an object instantiates into a scene, a save helper script on the newly spawned object would look for the main save script that would hold an array / list. The array / list size can be hard coded or dynamic it doesn’t matter as long as all data types can be converted to string and then parsed back to the original data type. You can technically look for the script first before spawning to make sure you have room, case its a fixed length. You can then choose to handle some of the data gathering on the Instantiated object by sending it to the save state script, or you can use the array / list to reference the object itself where it would gather the important data there. Very long story cut short the save script loops through the list looking for non null references converting any important data to string and packing it all to a long string that would be placed in a pref to written to a txt doc.
Dynamic loading - Once the scene starts up the string can be split and filled into the same array / list. Now we would read the list in a loop and use that unpacked data to spawn objects back where they came from, or doing what they were doing last time we were in that scene. When an object is destroyed in the scene the same save helper script on the g Obj would clean up its array element by removing the reference or setting it to null depending on how you have setup your save script. (eg) If the obj helper script has the functions for gathering lets say the pos, rot, and velocity on (ie) OnApplicationQuit the helper script would only need to know what element / Index to save to on the main save script therefore the helper script would reference the main save script instead of the other way around lol where the main scrip would reference the actual spawned object.
I even double pack data sometimes which is not a good term for it as packing is as you know a reference used often for compression. This would mean that each element is split and packed. I use this same procedure for saving to Sqlite as well although I think that’s kind of silly since Sqlite can be expanded in tables, rows and elements all on one db file.
I’ll try to answer any questions you have but be warned I’m a building machine that gathers only the info needed for my current projects, lol and have an even harder time explaining what I learned to others.
Thanks a million, I’ll have to look into dynamic saving and loading alongside Sqlite tonight, and if all goes well, it’ll be all done tomorrow Although… could I learn simple and dynamic PlayerPrefs in half a night? We’ll have to see, I guess.
Although… Now that I look at SQLite, I’m not sure if I should mess around with SQL databases for just a (simpler) mobile game.
Yeah, I actually didn’t watch that exact video but skimmed through the comments to see a glimpse of how in-depth the video went. However, I’m going to just guess that it’s probably an indirect reference to how the docs say .Save() typically causes a hiccup, so should be used at checkpoints or such.
Also, on the matter of dynamic data, how would you save a list? I’ve been going through all the options in the Doc and have successfully saved, loaded, and used a float and an int. However, I don’t see an option (like Get/SetList) for dynamic saving to a single PlayerPref (as Black Mantis mentioned).
Once again, thank you everybody for all the help. Didn’t expect to get even this much working so soon.
Hello again - There is an extended feature to playerPrefs found in a script on the wiki called arrayPrefs or something like that. It’s actually written by Eric5h5 . Good stuff but you can work around it by converting all your elements to string, then combining them to one big string.
I think I found at least something similar to it, but it seems I may just go with a sort of self-made array based systems for flexibility. I would have to still convert to float or int most of the time, so it won’t make much of a difference. All I have to do is append each of the levels with the scene name and I should have a good method if a bit disorganized for this.
Actually, I don’t even need an array system (where it’s “name” + or such). As I only have so many variables per level to store or use, and only so many other side variables, there’s not too much for me to manage. It would be similar to Application.loadedLevellName + variableName (although I may have to use a temporary variable each time as I’m not sure if PlayerPrefs would take such an argument). Well, time for testing, and all of this has helped me move forward in my project quite a bit.
How complicated is your system? I’ve been spending the more productive moments for the last hour and a half dedicated to project schedule management (so I can get this actually running with most functionalities if a little bare on content) in 7 days. Then I started to oddly also use a simplistic flow chart to chart out the save system.
It seems like my system isn’t complicated enough to use something like SQLite but complicated enough that I may have to use additional resources (saw WiNeTel’s post, THANK YOU!).
For me (not considering options and such yet):
a) Main Menu → b) or Continue button (goes to latest unlocked level)
b) World Menu → c) (must check if world is unlocked, going to use a linear system for now where you have to complete all the basic stages one by one)
c) Level Menu → d) (must check which levels are locked or unlocked, check how many secret items have been collected, maybe check for extra info)
d) The Level (Get high score, top time, time collected, and maybe any extra info)
Well, that’s all that’s needed for the save state management, and there are also other dependencies depending on the info collected (like if you find all the secret items, the “secret” level is unlocked, or if you get a new high score, say you got a new high score, etc). I think I may just use the current default PlayerPrefs, as it won’t even be that hard to convert a string to a bool indirectly (convert to int, if it’s 0 or 1 assign the bool that). Other than that, I won’t really need arrays.
This is actually very, very useful. Simplistic yet gives many more tools that I can easily use. However, I might as well use the current system I have… although now that I think about it, I still may have to come with around about methods that this could have solved
Well, here’s to hope that the day I submit to Android conversion and initial testing doesn’t go so bad I have to recreate these systems.
I agree it sound as if all you need is some PlayerPrefs and a lot of Gui lol. Most of my solutions are meant to be expanded dynamically. For anything under 20 variables its not really needed. If you need any help just let me know.
Honestly though, I think I may be able to make the jump to dynamic PlayerPrefs without much help once I’m done with this game. Now, if only I can get my menus to work properly and move on to the rest of my self-declared goals/deadlines for tonight…
I can sort of guess, but what types of things are you storing? I’m guessing you have dynamic environments and objects alongside a saving and loading system that isn’t linear (as in it isn’t only at the beginning or end of a level).