Cal W
Cal W

Reputation: 167

Unity load files from outside of resources folder

In unity is it possible to load a resource that is out side of the resources folder. I want the user to be able to set a textAsset variable from a file outside of the Assets directory entirely.

Upvotes: 2

Views: 11025

Answers (1)

Programmer
Programmer

Reputation: 125245

You can't load TextAsset from an external path(path not in the Unity game). In fact, you can't even load it from a path in the project itself which is not the Resources path which is then loaded with the Resources API.

One option you have is to use the AssetBundle. Add the TextAsset to the Assetbundle then you can load the Assetbundle from any path and extract the TextAsset from it.

If you just want to load any file outside the Unity path, you can do this without TextAsset. Just use any of the System.IO API such as File.ReadAllText an File.ReadAllBytes. This should be able to load your file.

Upvotes: 3

Related Questions