- Home /
How do I get the full path to an asset?
AssetDatabase.GetAssetPath returns me a path relative to the project directory. Application.dataPath returns me the absolute path to the data directory (usually inside the project).
I can't find the path of the project directory anywhere, though. I want to use it in conjunction with the asset path to have a full path. Anyone know how to get that?
Application.dataPath returns absolute path relative to building platform, it's different in iphone or android. Where is your asset located?
Answer by Waz · Sep 07, 2011 at 01:13 PM
Are you sure you want the full path? The Current Work Directory is set to the project directory, so you certainly can use a relative path when passing paths to system functions, etc.
Of course! I didn't realize the CWD was already set to the project path. It felt dirty to use the datapath and strip off the "assets" portion. Unity really should provide the project path explicitly rather than just setting it as the CWD.
Thanks, Warwick!
I guess the theory is to discourage us from storing absolute paths anywhere, thereby ensuring the project can be freely moved around the file system.
Answer by jonas-echterhoff · Sep 07, 2011 at 07:29 AM
Application.dataPath should work if you strip the "/Assets"
part of it. See the reference: It returns <path to project folder>/Assets
when called in the editor.
you're right if you're working just in editor.of course, you can hardcode other options too, but it's not the way. And another question is how you will put your asset into application folder(it has just read-access)? As i know, we can just write to Application.persistentDataPath, can't we?
"you're right if you're working just in editor." -- But AssetDatabase and the notion of an asset path only exists in the editor. And what do you mean by "just has read-access"? Of course you can write to the Assets directory.
ough, i didn't noticed assetdatabase. sorry about that.
I was thinking about following situation: we need to store some data(for example that comes from WWW), and we save it into persistentdatapath(because we don't have any other read-write-access folder). And we need to import some data in the build(let's say precache them:) ) using PostprocessBuildPlayer. But we don't know persistentDataPath in PostprocessBuildPlayer script . How to deal this?