calling Texture2DArray.SetPixels32 results in an "Invalid texture format: 12" error
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 [i].mipmapCount
new2darray.SetPixels32 (texs [i].GetPixels32 (), i);//this is where the problem is
//new2darray.SetPixels32 (texs [i].GetPixels32 (0), i, 0);
//new2darray.SetPixels (texs [i].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));
}
}
Answer by helpautism2 · May 22, 2017 at 10:34 PM
Have you made sure the texture is in RGBA32, ARGB32 formats? You can change that in the inspector of the texture file.
I can set it to RGBA 32 bit, but that almost quadruples the size. I haven't tested it out yet, I'll do it as soon as I get a chance.
Your answer
Follow this Question
Related Questions
How to change Texture in editor 0 Answers
How to get Color32 block from a runtime generated Texture2D? 0 Answers
Texture drawing on the wrong side of a mesh 0 Answers
Unity seems to be in 2D, but I want it in 3D 1 Answer
How do I use a sliced 2D sprite as the repeating texture on a 3D object? 0 Answers