Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Building a game for iphone and is not working properly

Discussion in 'iOS and tvOS' started by Pavlos_Mavris, Dec 1, 2019.

  1. Pavlos_Mavris

    Pavlos_Mavris

    Joined:
    Sep 17, 2018
    Posts:
    57
    I just started developing a game for iOS and I have an issue.
    The game is working perfect when i'm testing in inside the unity engine but when I build it on my iphone some mechanics are not working, but inside unity they work fine. If this is any iOS development thing that is deferent from android please tell me so I can search more about it.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. Pavlos_Mavris

    Pavlos_Mavris

    Joined:
    Sep 17, 2018
    Posts:
    57
    The game it supposed to create a file to save data about the game like the coins of the player and the current stage that the player is, but when I run it through xcode I'm getting the message that the file is not found but when I test it on unity it works fine.
     
  4. Pavlos_Mavris

    Pavlos_Mavris

    Joined:
    Sep 17, 2018
    Posts:
    57
    That's my code that i'm using!!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.IO;
    3. using System.Runtime.Serialization.Formatters.Binary;
    4.  
    5. public static class SaveSystem
    6. {
    7.  
    8.     public static void SavePlayer(GameManager player)
    9.     {
    10.         BinaryFormatter formatter = new BinaryFormatter();
    11.         string path = Application.persistentDataPath + "other.doll";
    12.         FileStream stream = new FileStream(path, FileMode.Create);
    13.  
    14.         PlayerData data = new PlayerData(player);
    15.  
    16.         formatter.Serialize(stream, data);
    17.         stream.Close();
    18.  
    19.     }
    20.  
    21.     public static PlayerData LoadPlayer()
    22.     {
    23.         string path = Application.persistentDataPath + "other.doll";
    24.  
    25.         if(File.Exists(path))
    26.         {
    27.             BinaryFormatter formatter = new BinaryFormatter();
    28.             FileStream stream = new FileStream(path, FileMode.Open);
    29.  
    30.             PlayerData data = formatter.Deserialize(stream) as PlayerData;
    31.             stream.Close();
    32.  
    33.             return data;
    34.         }
    35.         else
    36.         {
    37.             Debug.LogError("Save file not found in " + path);
    38.             return null;
    39.         }
    40.     }
    41.  
    42. }
    43.  
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What is the debug output, specifically the value for path on iOS
     
  6. Pavlos_Mavris

    Pavlos_Mavris

    Joined:
    Sep 17, 2018
    Posts:
    57
    /var/mobile/Containers/Data/Application/11B31953-FABB-4E98-AB0A-3A10D3CFD74D/Documentsplayer.troll

    That's the path that xcode shows me
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, I believe you can see the issue from the path, you have a character missing and the file name is not other.doll
     
  8. Pavlos_Mavris

    Pavlos_Mavris

    Joined:
    Sep 17, 2018
    Posts:
    57
    I noticed the file name and I changed it, but it didn't work. What about the character missing?
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So here's a hint. In your message, for the filename it says Documentsplayer.troll , all one word.
     
  10. Pavlos_Mavris

    Pavlos_Mavris

    Joined:
    Sep 17, 2018
    Posts:
    57
    Thank you so much, your hint it was all I needed.
    My mistake was when I set the name of the file that I wanted to be actually it needs "/", like this "/player.troll".
     
    JeffDUnity3D likes this.