I want to be able to do something like this:

public FileInfo XmlBehaviourFile; 

And then use the asset browser in the Unity editor to select an asset. Ideally, I would like to limit it to XML files but that isn't too important.

I am aware of TextAsset but I can only access either a string or byte array of the contents. I can probably make this work, but at the moment, my library takes a FileInfo and handles the reading itself.

Is there a Type I can use that will make Unity let me choose a file in the editor and then simply store the path (ideally, it would handle making sure the path is relative and including the asset in the build).

Alternatively, would it be possible to write such a type that would work, I've not extended Unity, but I am aware it is possible.

  • 3
    \$\begingroup\$ you can't serialize and expose directly a FileInfo. Btw, since what you need is a path you can expose a string and write a custom property drawer forcing the inspector to open a file browser. \$\endgroup\$
    – Heisenbug
    Dec 9, 2013 at 14:06
  • \$\begingroup\$ The latter suggestion sounds exactly like what I need, I shall look in to custom property drawers \$\endgroup\$
    – T. Kiley
    Dec 9, 2013 at 14:09

1 Answer 1


I think it's a bad idea to store the path; if you want to pick it from the asset browser, then your file is handled by the asset database, and referencing it through this is much better: it will automatically get gathered into builds, you can move or rename it, etc.

So, the real question is, why do you need a FileInfo? Note that in a build, the file won't exist as far as the OS is concerned, it will be part of a bigfile (Unity packages all the assets into one giant sharedAsset file). So if you need to read the file in builds, you will need to change your API to accept a string or TextAsset directly.

If you need to read the file at editor-time, you can use AssetDatabase.GetAssetPath() to get the file path, then the FileInfo. But again, won't work in builds.

Now if your XML files were outside of the asset database (outside of the project/Assets folder), like if you plan on getting them from a server or whatever, then it's a different issue...

Lastly... are you sure you need an XML file? couldn't you use a ScriptableObject instead?


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .