How to load and get XML File path in a build unity Android project

615 Views Asked by At

I'm making VR game for oculus quest 2, and I need the build project to contain XML files so that the code can read them during the gameplay. I put the xml file in the "Resources" folder and load it with

string gestureFiles = Resources.Load("IceAttack").ToString();

The resource is being loaded successfully in the build, but then I need to feed a function with the path of my loaded xml file, and I can't figure out how to do that

trainingSets.Add(GestureIO.ReadGestureFromFile(gestureFiles));

I've been following a tutorial, where the xml files were loaded with the code below, but it only works in the editor mode and not in the build project

string[] gestureFilesOld = Directory.GetFiles(Application.persistentDataPath, "*.xml");

My output right now returns this when I debug gestureFiles enter image description here

I need gestureFiles to return this to feed it in the function as string (But with the correct data path of my xml file in the build game) enter image description here

1

There are 1 best solutions below

0
Topher On

Resources and PersistentDataPath are two completely different things. Resources are packaged with your app when you build it (and it can be any type of file). PersistentDataPath is the location on the end-device where the application can store files during and between runtimes. You cannot pre-load PersistentDataPath with any files.

In your call,

string gestureFiles = Resources.Load("IceAttack").ToString();

you actually have loaded the contents of the file. That's not the location of the file. A more accurate naming would be:

string gestureXMLString = Resources.Load("IceAttack").ToString();

Now, I'm assuming that the following is expecting a filename to load.

trainingSets.Add(GestureIO.ReadGestureFromFile(gestureFiles));

So, you would want something to the effect of:

trainingSets.Add(GestureIO.ReadGestureFromXMLString(gestureXMLString));

That method would parse an already loaded XML string.