• 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 darynlim · Dec 06, 2013 at 08:44 AM · gameobjecttransform.position

Gameobject Position to XML

Hi, I created a empty gameobject that stores all 4 sphere in it. How do I place all 4 sphere position into a XML file?

Currently I am able to read the 4 sphere position

  foreach (Transform child in Root.transform)
     Debug.Log(child.transform.position);

Than I create a new XML file // Create subfolder

         System.IO.Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"/Assets");
         
         // Declaration
         XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", null, null);
         xmlDoc.AppendChild(dec);
         
         // Create the root element
         XmlElement root = xmlDoc.CreateElement("Vechicles");
         xmlDoc.AppendChild(root);
         
         xmlDoc.Save(filepath);
         
         Debug.Log("File Created");

How do I store the 4 sphere position into the newly created XML file?

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 Fornoreason1000 · Dec 06, 2013 at 08:54 AM 0
Share

a position is just 3 floating point integers, store it like you would an array.

[x,y,z]

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by karljj1 · Dec 06, 2013 at 08:55 AM

Wrap it up into a serializable class.

http://support.microsoft.com/kb/815813

 [System.Serializable]
 public class MyPositions
 {
     public Vector3[] positions;
 }
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 darynlim · Dec 09, 2013 at 02:13 AM

Hi I'm not too sure how the serialization works. I tried the following but it gave me error

 public GameObject Root = null;

 public class MyPositions
 {
     public Vector3[] positions;
 }    

 // Use this for initialization
 void Start () 
 {
     SerializeToXML();
 }

 public void SerializeToXML(MyPositions position)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(MyPositions));
     TextWriter textWriter = new StreamWriter(@"C:\Position.xml");
     serializer.Serialize(textWriter, position);
     textWriter.Close();
     Debug.Log("okay");
 }
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

18 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

Related Questions

Subtracting the position of transform from the position of Game Objects in a list. 1 Answer

Network Lag 1 Answer

Align Parent object using child object as point of reference 3 Answers

Can't set the transform.position of imported objects correctly 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 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