Working with Textures on Android

Hello, I am trying to create 3d graphical redactor for Android, but there are some problems with the reading textures procedure. There are several predefined textures saved as png in the Resources folder. Users can set them to meshes of some objects. While testing the app in the editor the code loads them fine. Here is the code

...
        ReadTexture("/Resources/Player/Texture1.png")
...

private Texture2D ReadTexture(string path)
    {
        var bytes = System.IO.File.ReadAllBytes(Application.dataPath + path);
        Texture2D texture = new Texture2D(10, 10);
        texture.LoadImage(bytes);
        return texture;
    }

But on my Android device, it does not work. Using the adb I even did not see the png files in the application path. Why is it happen? I would be very glad for any help

check device log, its usually wrong path

since in android that path is probably not directly accessible

1 Like

This will never work anywhere but in the Unity editor. Don’t do this unless it’s just an editor script.

For pre-made stuff use direct drag-and-drop references, or Resources.Load() (read all the requirements!)

If you want to actually ship binary PNG files out, you can put them in StreamingAssets and read them. Each platform is a little different loading code.

1 Like