So I have a script that take several Texture2D objects and uses the data to create a Texture2DArray. The problem is that whenever it get to the SetPixels32 method I get two error messages that both say “Invalid texture format: 12” followed by another error that says “Image invalid format!”, followed by another two “Invalid texture format: 12” errors, and so on until It’s given me sixteen of the “Invalid texture format: 12” errors and eight of the “Image invalid format!” errors. The documentation hasn’t been helpful in determining the cause. It can’t be a null reference error because I’ve made sure that none of the textures are empty in the editor.
I’m pretty much stuck at this point. Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TextureArrayTesting : MonoBehaviour {
public Material ArrayMaterial;
public Texture2D AOTex1, AOTex2, AOTex3, AOTex4, NormTex1, NormTex2, NormTex3, NormTex4;
private void makeTextureArray(string arrayName, params Texture2D[] texs){
Texture2DArray new2darray = new Texture2DArray (texs [0].width, texs [0].height, texs.Length, texs [0].format, true);
for (int i = 0; i < texs.Length; i++) {
//texs *.mipmapCount*
new2darray.SetPixels32 (texs .GetPixels32 (), i);//this is where the problem is
//new2darray.SetPixels32 (texs .GetPixels32 (0), i, 0);
//new2darray.SetPixels (texs .GetPixels (), i);
}
ArrayMaterial.SetTexture (arrayName, new2darray);
}
// Use this for initialization
void Start () {
makeTextureArray (“_BumpMapArray”, NormTex1, NormTex2, NormTex3, NormTex4);
makeTextureArray (“_AO_Array”, AOTex1, AOTex2, AOTex3, AOTex4);
ArrayMaterial.SetVector(“_BlendingValues”, new Vector4(0.2f, 0.6f, 0.35f, 0.42f));
}
}