Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by zak666 · Jan 06, 2017 at 09:06 AM · savepersistence

MAC - Hey Gang trying to create a Save file, what am I doing wrong here? FileNotFoundException: Could not find file "/Users/zak/Library/Application Support/M2H/PhotonUnity/gameInfo.dat"

Trying to create and load a save game file for my game however I'm running into an error: FileNotFoundException: Could not find file "/Users/zak/Library/Application Support/M2H/PhotonUnity/gameInfo.dat"

Also will a fix also work on windows builds?

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.IO;
 using UnityEngine.UI;
 public class SaveSystem : MonoBehaviour {
 
     public GameObject Loggedin;
     public GameObject LoggedOut;
     public GameObject NoUsername;
     public GameObject MissionControll;
 
     public Text Username;
     public PlayerData dataP;
     public PlayerStats Stats;
 
     public void Start () {
         Stats = MissionControll.gameObject.GetComponent<PlayerStats> ();
     }
 
     public void Save() {
 
         if (Username != null) {
             dataP.Username = Username.text.ToString ();
             BinaryFormatter bf = new BinaryFormatter ();
             FileStream file = File.Open (Application.persistentDataPath + "/gameInfo.dat",
                                 FileMode.Open);
 
             PlayerData data = new PlayerData ();
             data.XP = Stats.Xp;
             data.SG = Stats.SG;
             data.RS = Stats.RS;
             data.LVL = Stats.LVL;
 
             //small ships
             data.Ship01 = Stats.Ship01;
             data.Ship02 = Stats.Ship02;
             data.Ship03 = Stats.Ship03;
             data.Ship04 = Stats.Ship04;
             data.Ship05 = Stats.Ship05;
             data.Ship06 = Stats.Ship06;
 
             //medium ships
             data.Ship001 = Stats.Ship001;
             data.Ship002 = Stats.Ship002;
 
             //heavy ships
             data.Ship0001 = Stats.Ship0001;
             data.Ship0002 = Stats.Ship0002;
 
             //Capital ships
             data.Ship00001 = Stats.Ship00001;
             data.Ship00002 = Stats.Ship00002;
 
             //Science Ships
             data.Ship000001 = Stats.Ship000001;
             data.Ship000002 = Stats.Ship000002;
             data.Ship000003 = Stats.Ship000003;
             data.Ship000004 = Stats.Ship000004;
 
             //Skills Russian
             data.SkillsR01 = Stats.SkillsR01;
             data.SkillsR02 = Stats.SkillsR02;
             data.SkillsR03 = Stats.SkillsR03;
             data.SkillsR04 = Stats.SkillsR04;
             data.SkillsR05 = Stats.SkillsR05;
 
 
             //Skills American 
             data.SkillsA01 = Stats.SkillsA01;
             data.SkillsA02 = Stats.SkillsA02;
             data.SkillsA03 = Stats.SkillsA03;
             data.SkillsA04 = Stats.SkillsA04;
             data.SkillsA05 = Stats.SkillsA05;
         
             bf.Serialize (file, data);
             file.Close ();
         }
         NoUsername.SetActive (true);
 }
 
 public void Load() {
     if(File.Exists(Application.persistentDataPath + "/gameInfo.dat")) {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Open(Application.persistentDataPath + "/gameInfo.dat",
             FileMode.Open);
         PlayerData data = (PlayerData)bf.Deserialize(file);
         file.Close();
 
             Stats.Username = data.Username;
             Stats.Xp = data.XP;
             Stats.SG = data.SG;
             Stats.RS = data.RS;
             Stats.LVL = data.LVL;
 
             //small ships
             Stats.Ship01 = data.Ship01;
             Stats.Ship02 = data.Ship02;
             Stats.Ship03 = data.Ship03;
             Stats.Ship04 = data.Ship04;
             Stats.Ship05 = data.Ship05;
             Stats.Ship06 = data.Ship06;
 
             //medium ships
             Stats.Ship001 = data.Ship001;
             Stats.Ship002 = data.Ship002;
 
             //heavy ships
             Stats.Ship0001 = data.Ship0001;
             Stats.Ship0002 = data.Ship0002;
 
             //Capital ships
             Stats.Ship00001 = data.Ship00001;
             Stats.Ship00002 = data.Ship00002;
 
             //Science Ships
             Stats.Ship000001 = data.Ship000001;
             Stats.Ship000002 = data.Ship000002;
             Stats.Ship000003 = data.Ship000003;
             Stats.Ship000004 = data.Ship000004;
 
             //Skills Russian
             Stats.SkillsR01 = data.SkillsR01;
             Stats.SkillsR02 = data.SkillsR02;
             Stats.SkillsR03 = data.SkillsR03;
             Stats.SkillsR04 = data.SkillsR04;
             Stats.SkillsR05 = data.SkillsR05;
 
 
             //Skills American 
             Stats.SkillsA01 = data.SkillsA01;
             Stats.SkillsA02 = data.SkillsA02;
             Stats.SkillsA03 = data.SkillsA03;
             Stats.SkillsA04 = data.SkillsA04;
             Stats.SkillsA05 = data.SkillsA05;
 
             LoggedOut.SetActive (false);
             Loggedin.SetActive (true);
     }
 }
 
 }
 
 
 [Serializable]
 public class PlayerData {
     // TODO: see about making gets and sets.
     // TODO: automate the generation of this data structure.  See:
     // http://forums.devx.com/showthread.php?170650-How-to-dynamically-add-property-to
 
     // Add new variables for loading and saving here.
     public string Username;
     public int XP;
     public int LVL;
     public int SG;
     public int RS;
 
     public int Ship01;
     public int Ship02;
     public int Ship03;
     public int Ship04;
     public int Ship05;
     public int Ship06;
 
     public int Ship001;
     public int Ship002;
 
     public int Ship0001;
     public int Ship0002;
     public int Ship0003;
     public int Ship0004;
 
     public int Ship00001;
     public int Ship00002;
 
     public int Ship000001;
     public int Ship000002;
     public int Ship000003;
     public int Ship000004;
 
     public int SkillsA01;
     public int SkillsA02;
     public int SkillsA03;
     public int SkillsA04;
     public int SkillsA05;
 
     public int SkillsR01;
     public int SkillsR02;
     public int SkillsR03;
     public int SkillsR04;
     public int SkillsR05;
 }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KoenigX3 · Jan 06, 2017 at 04:00 PM

The saving function does not check if the 'gameInfo.dat' file exists or not. I assume, that you have not created the file in the first place.

You should use these lines:

 FileStream file;
 if(File.Exists(Application.persistentDataPath + "/gameInfo.dat")) file = File.OpenWrite(Application.persistentDataPath + "/gameInfo.dat");
 else file = File.Create(Application.persistentDataPath + "/gameInfo.dat");
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

61 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Persistent data, Save file doesn't come out as hoped 1 Answer

Can you make Mesh manipulations persistent? 2 Answers

SerializationException: Type UnityEngine.UI.Button is not marked as Serializable. Solution 1 Answer

Complicated save problem 2 Answers

Chest contents persistence between scenes 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