- Home /
Can't load external XML in browser
I'm using an external XML file to load unit stats in the game, it works well in Unity editor and when compiled to desktop, but in the browser it gets stuck. I'm using this code:
WWW www = new WWW(URL);
while(!www.isDone) {} //I know busy wait is evil, didn't find the right way to do this yet
StringReader s = new StringReader(www.text);
XmlDocument xmlData = new XmlDocument();
xmlData.Load(s);
XmlNode Units = xmlData.SelectSingleNode("GameSettings/Units");
I believe it gets stuck on the busy wait line - but if I remove it I simply don't get nothing loaded. I've tried to play with cross domain access settings but I'm not sure how those should be working with Unity. Any help would be greatly appreciated!
Answer by Graham-Dunnett · May 07, 2013 at 08:00 PM
In c# use yield return www;
to wait for the content to be fetched (exactly as the documentation shows). Once the request has been made, print out using Debug.Log()
the www.text
. That should tell you if the xml has been fetched or not. Also, the Player.log
will tell you if there are security problems.
I'm recalling now why I didnt use yield in the first place. I get this error when I do:
The body of
GameLogic.UnitsTable.LoadFromURL(string)' > cannot be an iterator block because >
void' is not an iterator interface type
Also, I don't have a Player object I can use to log the errors you've described. Thanks.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Save/Load game using XML on Browser/Web Player 2 Answers
Runtime instantiation based on XML 1 Answer
XML AppendChild not working 0 Answers
XML Check if a node exists 3 Answers