• 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
Question by BinHexer · Nov 24, 2020 at 10:11 PM · editorserializationsavingdata storagebinaryformatter

Binary Serialization (In Editor) - Path Access denied / File not found

Hey fellow developers,

I am trying to use common Serialiation to save and load data in a file. I've used this method countless times and it worked flawlessly every time. But in this project, for some reason, it does not work.

What may be important: I am trying to save and load in EDITOR, so NOT at runtime. Does that cause any issues? The save data is a class LevelData that contains a list of TrafficScene. TrafficScene holds ints, strings and a SceneAsset. Does the SceneAsset type cause any issues? Both classes are marked as Serializable. Both do not inherit from anything. I am either getting a Path Access Denied error or a File not found error. Here are my save and load methods:

     public void LoadLevelData()
     {
         FileStream file = null;
 
         try
         {
             BinaryFormatter bf = new BinaryFormatter();
 
             file = File.Open(Application.dataPath + data_Path, FileMode.Open);
 
             levelData = (LevelData)bf.Deserialize(file);
 
             if (levelData != null)
             {
                 levels = levelData.Levels;
             }
 
             Debug.Log("Successfully loaded");
         }
         catch (Exception e)
         {
             Debug.LogWarning("Loading Warning" + e.Message + e + e.InnerException);
         }
         finally
         {
             if (file != null)
             {
                 file.Close();
             }
         }
     }
 
     public void SaveLevelData()
     {
         FileStream file = null;
 
         try
         {
             BinaryFormatter bf = new BinaryFormatter();
 
             file = File.Create(Application.dataPath + data_Path);
 
             if (levelData != null)
             {
                 levelData.Levels = levels;
 
                 bf.Serialize(file, levelData);
             }
 
             Debug.Log("Data saved");
         }
         catch (Exception e)
         {
             Debug.LogWarning("Saving Warning" + e.Message + e + e.InnerException);
         }
         finally
         {
             if (file != null)
             {
                 file.Close();
             }
         }
     }


One of the errors:

 Loading WarningCould not find file "C:\Users\Lukas\AppData\LocalLow\LoopGameDev\Traffic Gameleveldata.dat"System.IO.FileNotFoundException: Could not find file "C:\Users\Lukas\AppData\LocalLow\LoopGameDev\Traffic Gameleveldata.dat"
 File name: 'C:\Users\Lukas\AppData\LocalLow\LoopGameDev\Traffic Gameleveldata.dat'
   at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0019e] in <9577ac7a62ef43179789031239ba8798>:0 
   at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <9577ac7a62ef43179789031239ba8798>:0 
   at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
   at System.IO.File.Open (System.String path, System.IO.FileMode mode) [0x00000] in <9577ac7a62ef43179789031239ba8798>:0 


Now it also tells me:

 Saving WarningType 'UnityEditor.SceneAsset' in Assembly 'UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.System.Runtime.Serialization.SerializationException: Type 'UnityEditor.SceneAsset' in Assembly 'UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.


Does anybody know a fix? I really do not know why it's not working. I assume it's cause I'm not at runtime, but in Editor. I am using 2020.1.12f1 and this is a Collab project with 2 people working on it.

I highly appreciate any help! Stay safe and cheers!

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

194 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is EditorUtility.SetDirty restricted to prefabs or inspected GameObject? 5 Answers

Serialization Exception Error When Trying to Load 2 Answers

I am getting a serialization exception error when trying to save and load in Unity? 2 Answers

IOException: Sharing violation on path 1 Answer

How do you save changes made with custom editor? 3 Answers


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