Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Spεci · Nov 11, 2014 at 06:42 AM · serializationwindows phone

How do you serialize things on Windows Phone?

I've pretty much done the serialization as in the Mike Geig's live training video.

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading

The thing is that Unity allows me to build my project on Android. But when I try to build it on Windows Phone it says that System.Runtime.Serialization doesn't have Formatters.

So how do you do serialization on Windows Phone?

Here's my code:

 using UnityEngine;
 using System;
 using System.IO;
 using System.Collections;
 using System.Runtime.Serialization.Formatters.Binary;
 
 public class SaveIt : MonoBehaviour {
 
     public float health = 0;
     public float mightyPowers = 0;
 
     public void Save()
     {
         Debug.Log("Saving");
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Create(Application.persistentDataPath + "/player.dat");
 
         PlayerData data = new PlayerData();
         data.health = health;
         data.mightyPowers = mightyPowers;
 
         bf.Serialize(file, data);
         file.Close();
     }
     
     public void Load()
     {
         BinaryFormatter bf = new BinaryFormatter();
         if (File.Exists(Application.persistentDataPath + "/player.dat")) 
         {
             Debug.Log("Loading " + Application.persistentDataPath + "/player.dat");
             FileStream file = File.Open(Application.persistentDataPath + "/player.dat", FileMode.Open);
             PlayerData data = (PlayerData) bf.Deserialize(file);
             file.Close();
 
             health = data.health;
             mightyPowers = data.mightyPowers;
         }
     }
 
     // Use this for initialization
     void Start () {
         Load();
     }
 }
 
 [Serializable]
 class PlayerData {
     public float health;
     public float mightyPowers;
 }
 
Comment
Add comment · Show 4
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 Mike-Geig ♦♦ · Nov 12, 2014 at 02:26 PM 0
Share

It's possible that the libraries that the windows phone uses aren't the same. Since WP uses .NET 4.x, take a look at those libraries and see where the serializer classes are and how they are used. That is the main difference between WP and iOS/Android

avatar image Vekoro · May 25, 2015 at 02:03 PM 0
Share

$$anonymous$$ike Geig, could you explain how to save on Windows Phone 8? I have the same problem, i was following the live training too.

avatar image Vekoro · May 26, 2015 at 09:06 AM 0
Share

I have the same problem. I got the same code from the live training. I can build the game, but i become an error:


Reference Rewriter: Error: method System.Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter::Deserialize(System.IO.Stream) doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void GameControl::Load().

UnityEngine.Debug:LogError(Object) PostProcessWP8Player:RewriteReferencesForAssembly(String, String, String, String, String, String, String) (at C:/buildslave/unity/build/PlatformDependent/WP8Player/Extensions/$$anonymous$$anaged/PostProcessWP8Player.cs:450) PostProcessWP8Player:$$anonymous$$ake$$anonymous$$anagedAssembliesWp8Compatible(String, String, LibraryCollection) (at C:/buildslave/unity/build/PlatformDependent/WP8Player/Extensions/$$anonymous$$anaged/PostProcessWP8Player.cs:411) PostProcessWP8Player:PostProcess(BuildTarget, BuildOptions, String, String, String, String, String, Guid) (at C:/buildslave/unity/build/PlatformDependent/WP8Player/Extensions/$$anonymous$$anaged/PostProcessWP8Player.cs:212) UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

avatar image Spεci · Jun 04, 2015 at 07:08 AM 0
Share

Hello Vekoro! I ended up using a commercial plugin called Easy Save 2. https://www.assetstore.unity3d.com/en/#!/content/768

With the plugin you can do serialization on the Windows Phone. But I'm not completely sure if it's the fastest solution when considering performance.

Let's hope that we will have better performance with WP 10 in overall when compared to other mobile platforms.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Array of arrays = No serialization? 4 Answers

Unbound Objects Are Not Null? 0 Answers

Serialization errors.. 0 Answers

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

Unity object cloning and public/private variables 0 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