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 gpollak450 · Sep 03, 2016 at 05:00 PM · c#serializationlists

Unity build cant find serialized file after restarting

Hi! I'm creating a 2D Sandbox Game and i'm currently trying to add saving. I've Pretty much made it work. I'm using a serialized file to save the Players inventory and all the blocks and their positions. I serialize 7 lists that hold the blocks ID, Number, X position, and Y position, and the Inventory Items Slot, Number, and ID. But when I tested saving in a build, and try to load the serialized file after restarting the build, it won't load the file. I searched on Google for an answer and I think it has to do with serializing lists.

Here's my code for saving and loading called SaveLoad.cs

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic; 
 using System.Runtime.Serialization.Formatters.Binary; 
 using System.IO;
 
 
 public static class SaveLoad {
 
 public static Game savedGame;
 
 
 
 public static void Save () {
 
     savedGame = Game.current;
 
     if (Directory.Exists(Application.persistentDataPath + "/Saves")) {
     }
 
     else {
     Directory.CreateDirectory(Application.persistentDataPath + "/Saves");
     }
 
     BinaryFormatter bf = new BinaryFormatter();
     FileStream file = File.Create (Application.persistentDataPath + "/Saves/savedGame.save");
     bf.Serialize(file, SaveLoad.savedGame);
     file.Close();
 }
 
 public static void Load () {
 
 if (File.Exists(Application.persistentDataPath + "/Saves/savedGame.save")) {
 BinaryFormatter bf = new BinaryFormatter();
 FileStream file = File.Open(Application.persistentDataPath + "/Saves/savedGame.save", FileMode.Open);
 SaveLoad.savedGame = (Game)bf.Deserialize(file);
 
     Game.current.BlocksX.Clear();
     Game.current.BlocksY.Clear();
     Game.current.BlockNums.Clear();
     Game.current.IDs.Clear();
     Game.current.InvIDs.Clear();
     Game.current.Slots.Clear();
     Game.current.ItemNums.Clear();
 
 file.Close();
         }
     }
 
 }

if you need more Info just ask.

Comment
Add comment · Show 6
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 LTK · Sep 03, 2016 at 05:20 PM 0
Share

You tested with android platform?

avatar image gpollak450 · Sep 03, 2016 at 08:47 PM 0
Share

I'm making the game for PC.

avatar image Cherno · Sep 03, 2016 at 09:01 PM 0
Share

What-s the error message? Did you insert Debug.Log lines to check if the file was found? (De)Serializing Lists and other collections shouldn't be the problem.

avatar image gpollak450 · Sep 03, 2016 at 09:37 PM 0
Share

I don't think so. I'll try that.

avatar image gpollak450 · Sep 09, 2016 at 03:22 AM 0
Share

I added a debug message and it does find the file. but when i try to get the count of any list i get an object reference not set to an instance of an object error;

Show more comments

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.

Follow this Question

Answers Answers and Comments

219 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 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

SQLite and Lists in C# 1 Answer

Serialization Error 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Dictionary, List, Hashtable - Best Practices 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