Hi!
We have this very annoying bug: PlayerPrefs are not saved in Mac standalone. They’re saved ok in Win standalone, and in the Unity editor, so we know there’s no problem with our code.
We’ve reproduced it on 4 machines, but UT can’t reproduce it. We’re wondering if it could be a language issue (all our systems are in French)… seems far-fetched but you never know.
So if anyone can try our beta and report it here or in PM, we’d be grateful.
The test is super simple: start the game, enter your name, quit, start again: if it asks for your name again, the PlayerPrefs weren’t saved…
Simply report your OSX version language, and if the test succeeded or not.
I’m on 10.4.11 and in American English and it doesn’t save. Looking at the plist, nothing is in there besides the internal Unity preferences like resolution and quality settings. However, I’m pretty darn sure other games save fine and if it’s how I think they’re handling preferences on Mac, it’s really simple code.
If you look at the console.log while the game is running there are exceptions. That’s probably the problem and something you just need to fix.
DETAILED EXCEPTION
System.NullReferenceException:
at <0x00000> <unknown method>
at (wrapper managed-to-native) UnityEngine.Behaviour:set_enabled (bool)
at PopupBoxBase.Hide () [0x00000]
at PopupBoxManager.OnLevelWasLoaded () [0x00000]
DETAILED EXCEPTION END
NullReferenceException
PopupBoxBase.Hide ()
PopupBoxManager.OnLevelWasLoaded ()
(Filename: Line: 0)
Yeah I know it’s maddening!!!
I also have other games that save fine… Anyhoo thanks.
Still looking for more feedback, especially “working” ones, we seem to have plenty of non-working. We need to figure out in which case it works or doesn’t…
Edit: thanks for the console log, it’s due to a new line I added a couple days ago and didn’t notice. Unfortunately this PopupBoxManager is only a GUI thing (the window that prompts for the name), and has nothing to do with prefs. I fixed it anyway so thanks ;).
When you validate your name you’ll see the console says
saving preferences...
UnityEngine.Debug:Log(Object)
and then
preferences saved!
UnityEngine.Debug:Log(Object)
I put that to make sure that the function where I call PlayerPrefs.SetInt/String etc is called ok.
Anyway, again, it works on windows so I really think this is a problem with the engine, not my scripts.
I believe Unity directly uses OSX’s standard preferences API, which caches the changes in memory until the application quits. If you crash while quitting, they won’t get written.
It would be possible for Unity to explicitly flush the changes to disk on every change with this particular API, but that won’t solve your crash bug.
Thanks for the info, great stuff!
If they indeed use an OSX API, it feels less and less likely that language is the issue, I don’t see Apple messing that up.
About the “quit crash”, the only place I could see it come from is this one script that uses OnApplicationQuit.
I just removed it uploaded a new version: could you be so kind as to check it (same location), see if it still crashes?
To Jonathan : I also fixed the popup bug thing, but it still fails to save…
I’m getting exactly the same behaviour with the new build, unfortunately.
Are you doing anything with threads in your game? The stack trace in the log snippet I posted makes me wonder if you’re using threads in a way that makes the garbage collection routine crash. Unfortunately, I don’t know enough about the intricacies of threading to have more than a hunch about that.
In case it helps, the full console log (minus datestamps etc. for terseness) for your game looks like this:
I’d test it again, but I’m at work now, and we only have Tiger machines here. I can try again when I get home if you like.
It’s kinda better, but it apparently has quite a lot of latency between when an app posts a message and when it actually appears in the log, especially when a lot of logging is going on. Also, they’ve cleverly altered it so that you can’t select and copy part of a line from the main console listing; you can only select whole lines.
Finally found the problem, yay!!
Neil, you put me on the right track: I wasn’t explicitly using threads, but sockets, so I guess something similar was going on.
Anyway I managed to fixed it so thanks for your help all!