|
Hi!, I'm trying to load a XML file and so far I got it, but I get the infamous "text node can't appear in this state". Something to do with the BOM encoding. Anyways, I tried this: //-------------------------------------------------------------------------- import System.Xml; import http://System.IO; //-------------------------------------------------------------------------- function GetTextWithoutBOM(textAsset : TextAsset) { //-------------------------------------------------------------------------- function loadLevel(archXML : String){ var xmlDoc : XmlDocument = new XmlDocument(); var ta : TextAsset = Resources.Load("/Assets/Materials/XML/Levels/10/test.xml"); Debug.Log(ta); // --- Returns NULL always :( var noBom: String = GetTextWithoutBOM(ta); xmlDoc.LoadXml(noBom); //-------------------------------------------------------------------------- But now I geting an "Object reference not set to an instance of an object" error, and I realize with the "Debug.Log" line that "Resources.Load" never load the file (it's null always). But, I know that the path to the file is Ok, because, when I use just this: xmlDoc.LoadXml("test.xml"); - or - xmlDoc.LoadXml("/Assets/Materials/XML/Levels/10/test.xml"); It works fine but I get the "Text node canot appear in this state" error in the first character. What I'm doing wrong?? I'm stuck. Thanks
(comments are locked)
|
If your text asset is null, I'm not sure why you would expect anything after that to work. According to Unity's script reference, There's a little bit more explanation here. If you're used to specifying paths directly, this can seem like a bit of a hurdle, but setting this up carefully can make it much easier to port your game to other platforms, if that's something you have in mind. From there, Unity might expect that a text asset's file extension is "txt", but you're welcome to experiment with that on your own.
(comments are locked)
|
|
I see, doh!, I checked the script reference but didn't realize that the folder should be named Resources, I just thought it was an example. Anyways, I want to place a huge number of text files there, so I would like to have my folders a bit more organized, but it doesn't seem possible unless I use "LoadAssetAtPath", that doesn't work in standalone or web players. So this raises another question: is it possible to load textAssets with "Resources.Load" that is inside a subfolder that is located within the "Resources" folder? Example: text file is in: Assets/Resources/Levels/test.txt Is there a way to load that file other than using "LoadAssetAtPath"?. I tried with Resources.Load and it didn't work. Thanks You can have any number of resource folders, organized however you want, as long as they're all named "Resources". Just remember that you're ultimately loading them all by name and that, as a result, any dynamically loaded asset will need a unique name. If we suppose you have a bunch of maps in folders like "Chapter1", "Chapter2", and so on; you could create a "Resources" folder in each of those groups. Not especially clean, but it might be a little cleaner than dumping all of them in one folder. Or, you could use some sort of alphabetical scheme. A file named "maps" could be named "ch01_maps".
Apr 03 '12 at 12:01 AM
rutter
(comments are locked)
|

sudha says : Hai,my problem is that i'm unable to retrieve data through xml for webbuild but if i run the same in unity editor it's building successfully...need help...Thanks in advance