|
Post by Andrew on Aug 27, 2018 21:59:19 GMT
I have a problem with my game losing (keep from previous) WorldVariable data on android. While I'm playing a level and click the home button(on Android Phone) and quit the application, the current level (keep from previous) WorldVariable data does not save. It saves fine if I load a scene and quit (using home button) or if i use my in game quit button (Which calls ApplicationQuit()) Or if i play in the unity editor and quit half way through a level. My particular case: I have lots of small scenes each with 3 persistable collectibles (they are set up already using their own pref system) Problem: The collectibles pref system tracks on change(when collected). So If you play a level get a collectible, hit the home button on the android and quit; start the game up again and play the same level you'll find that the collectible is gone (as it should be) but the WorldVariable data did not save that change.(it will save the data if i load a scene before quitting or use in game quit button that calls ApplicationQuit() possible solutions: *i know that hitting the home button(Android) calls OnApplicationPause(bool) so maybe I can force the keepfrompervious data to save in that method.? void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
??????? }
} * does calling levelsetting.levelcontinue or levelsetting.levelreset save the worldvariable data? Can't really figure this one out any help is greatly appreciated.
|
|
|
Post by Andrew on Aug 27, 2018 22:35:40 GMT
I should also add that I'm just using The Worldvariables(from the LevelWavesSetting Prefab) from CoreGameKit as its a quick way to do persistence. the game does not use any other elements from the kit.
|
|
|
Post by DarkTonic Dev on Aug 28, 2018 0:50:51 GMT
There is a line of code that will flush the custom playerprefs we're using. Will look it up when I get home and tell you.
|
|
|
Post by Andrew on Aug 28, 2018 1:23:53 GMT
Thanks, I should add that I am only looking to save a couple worldvariables this way(I don't want my players to keep coins with out completeing a level, only collectibles).
i was looking to get the variables i want and updating the Playerprefs Setint when i add the collectibles. this is what i have but no clue if its even close to right.
//////////////// public string LvlStars;
public void collectstar() { var stars = WorldVariableTracker.GetWorldVariable (LvlStars); var Totalstars = WorldVariableTracker.GetWorldVariable ("TotalStars"); stars.CurrentIntValue += 1; Totalstars.CurrentIntValue += 1;
string tokenkeylvlstars = InGameWorldVariable.GetTokenPrefsKey (LvlStars); PreviewLabs.PlayerPrefs.SetInt (tokenkeylvlstars, stars.CurrentIntValue); string tokenkeytotalstars = InGameWorldVariable.GetTokenPrefsKey (LvlStars); PreviewLabs.PlayerPrefs.SetInt (tokenkeytotalstars, Totalstars.CurrentIntValue); }
|
|
|
Post by DarkTonic Dev on Aug 28, 2018 1:42:52 GMT
You're not going to need to do that. A 1-liner will save (and therefore re-load) the World Variables.
We currently have it in OnApplicationQuit in LevelSettings.cs
private void OnApplicationQuit() { AppIsShuttingDown = true; // very important!! Dont' take this out, false debug info will show up. WorldVariableTracker.FlushAll(); }
It sounds like you may need it in OnApplicationPause? Try adding the same FlushAll call to OnApplicationPause and let me know if it fixes. If so, I'll add it for Android only.
|
|
|
Post by Andrew on Aug 28, 2018 1:46:32 GMT
Ok the code snippet above that's mine was very wrong. saw your reply and tried PreviewLab.PlayerPrefs.Flush() and everything is working properly. Thanks again Love the tool!!!
|
|
|
Post by Andrew on Aug 28, 2018 1:51:19 GMT
ok so saw your reply with the different flush() i'll try that as well and let you know so you can make note of it.
|
|
|
Post by DarkTonic Dev on Aug 28, 2018 1:55:25 GMT
Let me know if that works. It should be the same thing.
Also show me your OnApplicationPause code (entire method) so I can add it for Android build only.
|
|
|
Post by Andrew on Aug 28, 2018 2:07:42 GMT
Ok put it right after OnApplicationQuit() in your Levelsettings code and everything's working great. Maybe this could be a bool option as some games may not want this behavior.
// ReSharper disable once UnusedMember.Local private void OnApplicationQuit() { AppIsShuttingDown = true; // very important!! Dont' take this out, false debug info will show up. WorldVariableTracker.FlushAll(); } private void OnApplicationPause() { AppIsShuttingDown = true; // very important!! Dont' take this out, false debug info will show up. WorldVariableTracker.FlushAll(); }
|
|
|
Post by DarkTonic Dev on Aug 28, 2018 3:15:53 GMT
Thanks!
|
|