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 bewilderstudiosgames · Aug 01, 2018 at 12:31 AM · serializationloadsave datafilestream

serialization stream supports seeking but its length is 0

Hi! Having an issue with Serializables... I've been watching THIS VIDEO on how to save and load files, and yet it still doesn't manage to work for me.

This game is going on android and it might be different, but I want it to save when the app is tabbed out and load on the game start, I currently have it saving every second because I wanted to make sure it works.

Most of this code has nothing to do with this but some does.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System;
 using UnityEngine.Serialization;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;
 
 public class Click : MonoBehaviour {
 
     public float tobys;
     public int tobysPerClick;
     public ItemManager[] items;
     public float TobyPS;
     public TMPro.TMP_Text TobyDisplay;
     public TMPro.TMP_Text TobyPSDisplay;
     public ItemManager itemManager;
     public GameObject TobyFall;
     GameObject TobyClone;
     public Image Tobyimage;
     public Sprite[] sprites;
     public Settings settings;
     public static float TotalTobysCollected;
     public static float TotalTobysPerSecond;
     public static int TotalTobysPerClick;
 
     // Use this for initialization
     void Start () {
         StartCoroutine(AutoTick());
         if (File.Exists(Application.persistentDataPath + "/clickData.dat"))
         {
             // THIS LOADS THE FILE
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open(Application.persistentDataPath + "/clickData.dat", FileMode.Open);
             ClickData data = (ClickData)bf.Deserialize(file);
 
             TotalTobysCollected = data.Total_Tobys;
             TotalTobysPerClick = data.Total_Tobys_Per_Click;
             TotalTobysPerSecond = data.Total_Tobys_Per_Second;
             file.Close();
 
 
         }
         InvokeRepeating("UpdateTime", 0, 1.0f);
     }
 
     // Update is called once per frame
     void Update () {
 
         TobyPS = GetTobyPerSecond();
 
         TotalTobysCollected = tobys;
 
         TotalTobysPerClick = tobysPerClick;
 
         TotalTobysPerSecond = TobyPS;
     }
 
     void UpdateTime()
     {
 
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create(Application.persistentDataPath + "/clickData.dat");
 
         ClickData data = new ClickData();
         data.Total_Tobys = TotalTobysCollected;
         data.Total_Tobys_Per_Click = TotalTobysPerClick;
         data.Total_Tobys_Per_Second = TotalTobysPerSecond;
 
         bf.Serialize(file, data);
         file.Close();
     }
 }
 
 [Serializable]
 class ClickData{
     public float Total_Tobys;
     public float Total_Tobys_Per_Second;
     public int Total_Tobys_Per_Click;
     }


Comment
Add comment · Show 1
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 bewilderstudiosgames · Aug 01, 2018 at 12:35 AM 0
Share

Just a note that I removed some of the code as it had no relevance to the issue

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

90 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

Related Questions

Proper way to save Terrain for save game feature? 1 Answer

Save and load serialization problem 0 Answers

Using save options to create saves for toggle buttons, but won't compile! 1 Answer

Add an array to a class that has been Serialized with BinaryFormatter 1 Answer

Error when loading saved date : SerializationException: End of Stream encountered before parsing was completed. 2 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