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
0
Question by kennadi · May 13, 2011 at 09:03 AM · savefilesystemexternal

Is there possible to save scene gameobject data on external file? (not in the registry)

I got a system where i cans save object position in my scene. It saves in the computer registry. This means that i can load my saved scene up only in the same computer it was saved in. I want to create a system where i save a scene and all its data will be written on an external file. I can then pass this file around and someone else who runs the same program on another computer can load up the file and read all the gameobject position data from it.

Can it be done and if so then how? (my program is a standalone executable)

Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by vietnt · May 16, 2011 at 10:31 AM

You answered the question yourself.

You can export your data of object positions to an xml file or any format you want to. The application then read the file and populate objects with information stored.

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
avatar image
0

Answer by BitFish · Jun 05, 2012 at 10:45 PM

Ah ha! In fact, there is a more "optimized" way -- try this:

 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;

 string filePath = Application.dataPath + "position.dat";
 PositionData positionData;
 
 using(FileStream s = new FileStream(filePath, FileMode.Create) )
 {
    BinaryFormatter b = new BinaryFormatter();
    b.Serialize(s, positionData);
 }

BTW, I haven't tested this myself, so there may be errors, but I know this is a simple technique for doing what you are trying to do. Play around a bit and see how it goes.

Comment
Add comment · Show 1 · 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 Berenger · Jun 05, 2012 at 10:53 PM 0
Share

Scott Lowe : Here is the code I often use to quickly save some data to a file (you can call it http://data.txt, or data.xml, or data.gameSave -- the extension doesn't really matter). It uses xml as a format. I'm sure there is a more optimized way to do this! (It's in C#, I'm sorry if you need unityscript, I'm not very familiar with that).

 string filePath = Application.dataPath + "/ObjectPosition/data.gameSave";

PositionData positionData; // this is the container for the data you want to save -- see below

 System.Xml.Serialization.XmlSerializer serializer = new     XmlSerializer(typeof(PositionData));

 using (StreamWriter w = new StreamWriter(filePath))
 { 
     serializer.Serialize(w, positionData);
 }


...and here is your data container class

 public class PositionData
 {
     public Vector3 position;
     public string name;
     public int someNumber;
 }

$$anonymous$$e : Didn't know which came first, sorry

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

1 Person is following this question.

avatar image

Related Questions

Accessing local system ( File Browser ) 2 Answers

Problem whith save system,Problem whith save code 0 Answers

simple checkpoint/save/load system in javascript 4 Answers

Screenshot script not uploading PNG to server when used with key trigger 1 Answer

Prevent users from opening external data files 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