• 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 bionicnacho · Jan 28, 2013 at 04:07 AM · saveserializeunity serializer

UnitySerializer: Saving to file

Hello!

Using whydoidoit's serializer, is there any way to save the data to a file, so that somebody could send the file to someone else and they could open it in THEIR game?

Maybe inside the game data have a folder named "saves" and have them all in there? Also, how would i be able to let the user upload their save to a server, and let other osers downld them and open them in the game? If i can get it to save in files, i have an idea on how to achieve this.

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 bionicnacho · Jan 29, 2013 at 01:30 AM 0
Share

anyone? whydoidoit?

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by whydoidoit · Feb 01, 2013 at 01:42 AM

Yes UnitySerializer can write to a file with LevelSerializer.SerializeLevelToFile and then you can use LevelSerializer.LoadSavedLevelFromFile

You can also use the functions to upload and download from a server and you can save individual objects trees using both methods too... It's ideal for sharing avatars between players, for testing or showing someone else your levels (if you dynamically construct them). But they do have to have the same scripts and models as you (and preferably the same prefabs). So the answer to your question is yes, if you mean at runtime, in the same game, can two people play different people's levels.

LevelSerializer.SaveObjectTreeToFile() / LevelSerializer.SaveObjectTreeToServer or as Julien mentioned, you can just take the string or the byte[] it produces and write and read it anywhere you like :)

Comment
Add comment · Show 4 · 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
avatar image whydoidoit · Feb 01, 2013 at 01:42 AM 0
Share

You can also use the JSONLevelSerializer versions if you prefer a JSON string to compressed binary - up to you.

avatar image bionicnacho · Feb 02, 2013 at 02:28 AM 0
Share

perfect! I was using

 for(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName]) { 
    if(GUILayout.Button(sg.Caption)) { 
      sg.Load(); 
      Time.timeScale = 1;
      } 
 }

to load the games (from the pausemenu script). How can i do this for the LevelSerializer.LoadSavedLevelFromFile? Is there a way to get all the saved games in files, like how it works with playerPrefs? Also... Is there any way to make them save in a SPECIFIC location? like thegame.app/Contents/Saved Games/GA$$anonymous$$E?

Thanks!

avatar image whydoidoit · Feb 02, 2013 at 08:59 AM 0
Share

So as soon as you start with the files approach you are dealing with each game individually - except you can just serialize the list of SavedGames itself - that's what US does internally to write the data to PlayerPrefs.

     UnitySerializer.SerializeToFile(LevelSerializer.SavedGames, "somePath");

And then load it back using UnitySerializer.DeserializeFromFile

avatar image bionicnacho · Mar 15, 2013 at 07:28 PM 0
Share

Hello. I know it's been a long time but i just kind of left this for later and now i am back working on it. How would i be able to send these files to a server, and then read them back later?

avatar image
2

Answer by Julien-Lynge · Jan 30, 2013 at 03:23 AM

You can write to a file using the System.IO class. That isn't Unity specific, and there are plenty of tutorials on writing files in C#. I have no idea what whydoidoit's serializer is, but if it outputs a string you can easily write that to disk. You can then open it on the other end with System.IO. Again, many tutorials will show you how.

Here's a google search: https://www.google.com/search?q=c%23+write+to+file&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

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.

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

11 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

Related Questions

[SOLVED] Save System with Serialize multiple objects 2 Answers

UnitySerializer not saving properly/any longer 0 Answers

Save Data from Editor Script, Serialize Nested Class List 1 Answer

Fastest Way To Save/Load a SkinnedMeshRenderer at Runtime 0 Answers

Serialization in unity Iphone basic 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