Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Creating Texture2DArray as asset

Discussion in 'Shaders' started by defaxer, Aug 11, 2016.

  1. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    Hello!
    Trying to test new Unity Texture array feature, but it seems I'm missing something with texture2DArray creation as asset.
    I'm saving Texture2DArray using following code:
    Code (CSharp):
    1.         Object[] selection = Selection.objects;
    2.         Texture2D[] textures = new Texture2D[selection.Length];
    3.         for (int i = 0; i < textures.Length; i++)
    4.         {
    5.             textures[i] = (Texture2D)selection[i];
    6.         }
    7.  
    8.         Texture2DArray array = new Texture2DArray(textures[0].width, textures[0].height, textures.Length, textures[0].format, false);
    9.         for (int i = 0; i < textures.Length; i++)
    10.             array.SetPixels(textures[i].GetPixels(), i);
    11.  
    12.         array.Apply();
    13.         AssetDatabase.CreateAsset(array, "Assets/TextureArray.tarr");
    while asset is created fine, I can't assign it to my shader or script through inspector. Shader code copied from Unity Documentation, so I assume it's fine. Can anyone tell what am I doing wrong?
     
    jjbish likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,402
    Best guess is this:
    http://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html

    I haven't tried doing this yet and I find it odd that it lets you make an asset with a different extension if it doesn't support it, and that said asset shows up in the project view still. It's plausible that your .tarr extension is fine and that documentation is wrong.
     
  3. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    Thanks! I missed that line in documentation :) Knew that has something to do with extension, but didn't know which one to choose. It's weird that Unity is so extension-dependent. Anyway, that works fine now!