- Home /
Path for Assets/Textures folder File in Android
I want path for pngs exist in Assets/Textures folder for Android platform. I don't know this thing is possible or not, if not possible then what is other way exist for getting path for png files. I want to use that actual png files for other purpose.
I have one reference Application.dataPath but this variable behaving different way in Android platform as per my thinking.
Please suggest me preferred way to do this.
Answer by _Yash_ · Jul 21, 2016 at 11:43 AM
Everything inside Assets folder is packed in binary after build. It does not exist at any path, but if you want to access the png you can place this inside Resources folder and load it at runtime using Resources.Load and then use it.
or
change extention of png file to .byte and read it at runtime like this.
public TextAsset imageTA; // you can load it with Resources.Load<TextAsset>
Texture2D tex = new Texture2D(4, 4);
tex.LoadImage(imageTA.bytes);
GetComponent<Renderer>().material.mainTexture = tex;
What if I need path of png file in string?? How can I get actual path of data exist in Resources folder??
As I said, there is no path for assets, everything is serialized and stored. Resources folders are used when you have lots of assets( 1000 images for example ) and don't want to load all of them when unity start. This way this png file is not loaded when unity starts and you can still access it.
why .byte?
if you opt for .txt unity will try to convert bytes to UTF characters and might corrupt the original image bytes. When you use .byte everything will be intact and you can have your real image inside unity. but if you still want path to folder, sorry it does not exist.
if you want to save data for your app use Application.persistentDataPath
@Yash really thanks for your reply. I have around 80 images and I want to share selected image via common sharing feature. So what way I need to adopt as per your thinking??
Answer by Naphier · Jul 25, 2016 at 08:22 AM
If you plan to distribute these files with your build then use StreamingAssets. You will need to load them via the WWW class on Android, but can use System.IO on desktop. I believe WWW will work in the editor for this purpose too. StreamingAssets will not convert, pack, or change the file in any way.
Your answer
Follow this Question
Related Questions
Difference between Application.persistantDataPath Vs Application.dataPath 2 Answers
build file with one game and two game can access it 0 Answers
File paths on Android 0 Answers
How do I find a folder I can write data to on Android? 3 Answers
Access Unity assets natively on Android and iPhone? 0 Answers