Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Backward pieS · May 08, 2015 at 01:33 PM · saveloadpersistentdatapath

Saving no longer works on iOS

I released a Unity (4.6) game for iOS last year, and saved the player's level progression using a binary formatter. Everything worked fine, but this past week I've been working on an update and am seeing a strange breaking of the saving system (which I have not touched).

When I build/run the project in Xcode, if the game is not yet on the device (whether iPad or iPhone), saving works properly. If I build it again, saving no longer works. If I run the game from the device, saving no longer works.

I haven't been able to determine if the problem is with my Xcode project, or with the game itself (because maybe something has changed in recent iOS updates?).

Here's some of the code to show how I handle things. These are all from a "ManagerLevels" class attached to a game object in the level selection screen (it isn't a child of anything so shouldn't be getting destroyed).

 public static ManagerLevels levelControl;
 public static bool [] completedLevels = new bool[35];    // 35 so can use 1-34

 [Serializable]
 class LevelData {
     public bool [] completedLevels;
 }
 
 void Awake () {                                          // Simple Singleton
     if (levelControl == null) {
         DontDestroyOnLoad(gameObject);
         levelControl = this;
         Load();
     }
     else if (levelControl != this) {
         Destroy(gameObject);
     }
 }
 
 public static void Load() {
     if (File.Exists(Application.persistentDataPath + "/levelInfo.dat")) {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Open);
         LevelData data = (LevelData) bf.Deserialize(file);
         file.Close();
 
         completedLevels = data.completedLevels;
     }
     else {
         // If no save data, set all completed level bools false (to be safe)
         for (int i=1; i<(completedLevels.Length); i++) {
             completedLevels[i] = false;
            }
     }
 }

 public static void Save() {
     BinaryFormatter bf = new BinaryFormatter();
     FileStream file = File.Create(Application.persistentDataPath + "/levelInfo.dat");
 
     LevelData data = new LevelData();
     data.completedLevels = completedLevels;
     bf.Serialize(file, data);
     file.Close();
 }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Backward pieS · May 12, 2015 at 03:39 PM 0
Share

Okay, this is...interesting.

I added some OnGUI reporting boxes to the $$anonymous$$anagerLevels class to monitor the load/save behavior. When I push a new build from Xcode onto the device, the OnGUI reporting boxes are there on the screen (and saving works).

However, after stopping the game (through Xcode) and making sure it is closed on the device, when I start the game up on the device again, I'm not seeing any OnGUI boxes - it's as if the $$anonymous$$anagerLevels class isn't even running.

I'm trying to figure out how this might be happening...

avatar image walker_bohannan · Jun 25, 2015 at 06:06 PM 0
Share

Did you manage to resolve this issue?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Backward pieS · Jun 25, 2015 at 08:26 PM

Yes, I did solve it. I was missing the following line in the Awake method (before anything else inside):

Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");

Worked fine after adding that.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Obtaining the absolute path of Application.persistentDataPath 0 Answers

Saving and loading data from file 0 Answers

Serialization scripting error 1 Answer

C# Issues with either PlayerPrefs.SetVariable or UnityEvent.Invoke 1 Answer

How do I find a Prefab after I Replaced said Prefab? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges