Search Unity

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,342
    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!