- Home /
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
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.
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.
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
![](https://koobas.hobune.stream/wayback/20220613133939im_/https://answers.unity.com/themes/thub/images/avi.jpg)