Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ginaho96 · Oct 06, 2015 at 05:54 AM · xml

Loading xml without loops

Problem : I can load the values from my xml however the values are being loaded repeatedly for 4 times -- in this case i'm getting the person's position. however i do not see any loops in my method that could cause this. I would like to stop it at the first time when all players positions have been loaded. Any help will be much appreciated. Thanks!

My xml and code are as follows :

 <?xml version="1.0" encoding="utf-8"?>
     <character>
       <persons>
         < person id="0" name="James">
           <position x="0.1289005" y="0.8196044" z="0.03671255" />
         </person>
         
         <person id="1" name="Dean">
           <position x="0.07401515" y="0.8196141" z="-0.001237739" />
         </person>
     
     </persons>
     </character>

and a load xml method :

 void LoadXML()   {
 { path = Application.dataPath + name + ".xml";
    XmlDocument xmlDoc = new XmlDocument ();
     if (File.Exists (path)) {
     xmlDoc.Load (path);
             
 XmlNodeList nodeList =  xmlDoc.GetElementsByTagName("position");
             
             for(int i=0; i<nodeList.Count; i++){
                 
                 string x = nodeList[i].Attributes["x"].Value;
                 string y = nodeList[i].Attributes["y"].Value;
                 string z = nodeList[i].Attributes["z"].Value;
             
                 Debug.Log(x+" "+y+" "+ z);
                 
             }Debug.Log("stop");
             }
     }

The output looks something like this

 x , y , z (positions for person 1)
 x, y , z  (positions for person 2)
 stop
 x , y , z (positions for person 1)
 x, y , z  (positions for person 2)
 stop
 x , y , z (positions for person 1)
 x, y , z  (positions for person 2)
 stop
 x , y , z (positions for person 1)
 x, y , z  (positions for person 2)
 stop


Note * Im not using serializer here

Comment
Add comment · Show 7
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 Eno-Khaon · Oct 06, 2015 at 06:23 AM 0
Share

Simply to ensure that the context is clear, where are you calling LoadX$$anonymous$$L() from and do you have only one object in your scene running this script?

It's certainly a rudimentary line of questioning, but what you've provided offers no obvious hints as to what the problem might be (which is good for the code, but bad for what you're currently experiencing).

avatar image ginaho96 Eno-Khaon · Oct 06, 2015 at 07:45 AM 0
Share

$$anonymous$$y loadxml() script is from a script that loads and saves a user's position base on the getkeydown function. And yes, I have attached this game to only one object.

Base on my gut feeling (on why there is a repetition of 4) I'm actually thinking if its affected by the character, persons , person nodes which lead the the repetition in output. If so then how should i edit my loadxml method to get the results i want?

avatar image Eno-Khaon ginaho96 · Oct 11, 2015 at 07:49 PM 1
Share

If this still hasn't been resolved yet in any way, I'm curious about something else now.

You say that when you tried "Get$$anonymous$$eyDown()" it looped twice...

Are you running "Get$$anonymous$$eyDown()" (or similar) from OnGUI() or from Update()? OnGUI() would cause it to run twice, for example.

Show more comments

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

30 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 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

A node in a childnode? 1 Answer

Best way to save to playerprefs scriptableObjects 0 Answers

How do I use this XML reader? 1 Answer

XML Load unauthorized access 2 Answers

Serilaization queries 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