Search Unity

Packer.GetTexturesForAtlas returned textures are not readable anymore (Unity 5.1.1p2)

Discussion in 'Scripting' started by Gruguir, Jun 29, 2015.

  1. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    In Unity 4.6, i was used to access sprites atlases by name to encode them in png and reuse with custom materials.
    In Unity 5.1.1p2, the returned atlas are not read/write enabled and throw an exception, for example :
    Code (csharp):
    1. var tex : Texture2D[] = Sprites.Packer.GetTexturesForAtlas("ESS1Body");
    2. tex[0].GetPixels();
    UnityException: Texture 'SpriteAtlasTexture-ESS1Body-64x64-fmt5' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
    UnityEngine.Texture2D.GetPixels (Int32 miplevel) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/TextureBindings.gen.cs:277)
    UnityEngine.Texture2D.GetPixels () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/TextureBindings.gen.cs:270)
    SaveSpriteSheetScript.Start () (at Assets/_Epsilus/Scripts/Utilities/SaveSpriteSheetScript.js:25)
     
  2. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    the returned texture can be seen in the script's inspector but can't be read or saved to disk, any help appreciated

    Edit : Bug Report Case 708708
     
    Last edited: Jun 30, 2015
  3. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    I'm still struggling with this. Sprite Packer Policy example in the documentation didn't work until recently (see http://forum.unity3d.com/threads/sprite-packer-policy-example-doesnt-work.337076/#post-2213879)
    Now it just have an harmless error. Unity tells me that i have to create a custom sprite packer policy :

    @edunity2 So how to modify the sprite packer policy example to save generated atlases to disk ? Should there not be something like 'AtlasSettings.enableReadWrite' ? I'm not familiar with this, ist it more complicated ? Once again, it was working without modifications until Unity 5.
     
  4. mvargas

    mvargas

    Joined:
    Aug 27, 2013
    Posts:
    5
    Still no resolution on this?
     
    Gruguir likes this.
  5. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    @mvargas please let me know if you find a workaround
     
  6. mvargas

    mvargas

    Joined:
    Aug 27, 2013
    Posts:
    5
    We ended up with a solution in which we manually create a copy of the Texture2D, read the raw texture data into that new copy, apply, and copy pixels one by one. Ugly.

    I considered importing all the textures with the isReadable flag set, but this prevents these textures from supporting sprite atlases, which is not what we want at all.