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 Addyarb · Sep 08, 2015 at 04:51 AM · serializationfilestream

Serialization Issue (Data not updating)

I'll cut to the chase since the problem seems fairly simple and I'm guessing I'm just not experienced to see what I'm doing wrong. I followed a Unity tutorial on serialization and it worked great. Now I'm trying my hand at it and the values don't seem to be saving. Here are the lines I've narrowed my problem down to.

             File.Delete(Application.persistentDataPath + "/PlayerCount.dat");
             FileStream newFile = File.Create(Application.persistentDataPath + "/PlayerCount.dat");
             PlayerCount data = new PlayerCount();
             data.currentPlayerCount = data.currentPlayerCount + 1;
             Debug.Log(data.currentPlayerCount + 1); //This always = 2
             Debug.Log(data.currentPlayerCount); //This always = 1
             bf.Serialize(newFile,data);
             SaveParameters (pCountData.currentPlayerCount);
             newFile.Close();



Line 5 always = 1, and line 6 always = 2. Shouldn't line 5 = Line 6?

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 GameVortex · Sep 08, 2015 at 06:54 AM

The two lines are not equal because you log out two different things.

You create initialize the PlayerCount data on line 3. At that point the variables in PlayerCount is initialized to default values. data.currentPlayerCount initializes to have a value of 0.

On line 4 you add 1 to data.currentPlayerCount (= 0 + 1), making the value now 1.

Then on line 5 you log out the data.currentPlayerCount + 1 which is 2. You are not using the = sign anywhere on that line meaning that no value changes, you just log out what data.currentPlayerCount added with 1 is.

Then on line 6 you log out what data.currentPlayerCount is which is still 1, from the added value on Line 4.

PS: I am assuming you mixed up your note at the bottom because your comments in your code says the reverse (Line 5 = 2 and Line 6 = 1).

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

28 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

Related Questions

C# Serialization is working fine in Unity but not on Android 2 Answers

Can we merge multiple save files for easier management? 1 Answer

serialization stream supports seeking but its length is 0 0 Answers

"IOException: Sharing violation on path" when Loading Data to Overwrite Save 1 Answer

C# Serialization error on Mobile using FileStream 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