PackTextures() resultant texture completely black

Hey so I’m trying to create a spritesheet and it seems to work fine when I set the maximumAtlasSize arguement to a size where I know the final texture would not fit causing it to downsample. Other then setting that to something really large where I know that the final texture would fit, the sprite atlas shows up black but at the correct size.

I don’t know what’s going on

Here’s some of the code:

static void GenerateSpriteSheet()
{
Object textureObjects = (Object)Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets);
int textureCount = textureObjects.Length;
if (textureCount <= 0)
return;

Texture2D[] textures = new Texture2D[textureCount];
for (int i = 0; i < textureCount; ++i)
    textures _= (Texture2D)textureObjects*;*_

string newSpriteSheetPath = “Assets/Game Assets/Resources/Spritesheets/NewEntries/”;
// Texture
Texture2D packedTexture = new Texture2D(1024, 1024, TextureFormat.ARGB32, true);
Material newMaterial = new Material(Shader.Find(“Transparent/Cutout/Diffuse”));
Rect[] uvs = packedTexture.PackTextures(textures, 1, 1024);
newMaterial.mainTexture = packedTexture; //set the main texture of the newMaterial as the new packed textures…
packedTexture.Apply();
EditorUtility.CompressTexture(packedTexture, TextureFormat.ARGB32);
string fileName = newSpriteSheetPath + “NewSpriteSheet-Texture.png”;
byte[] bytes = packedTexture.EncodeToPNG();
File.WriteAllBytes(fileName , bytes);
AssetDatabase.ImportAsset(fileName );
packedTexture= (Texture2D)AssetDatabase.LoadMainAssetAtPath(fileName );
*EditorUtility.SetDirty(packedTexture); *
AssetDatabase.ImportAsset(fileName );
AssetDatabase.CreateAsset(newMaterial, newSpriteSheetPath + “NewSpriteSheet-material.mat”);
AssetDatabase.SaveAssets();
}

Ha okay so I stumbled over it.

I had the textures to be packed set to read/writable enabled but turns out that flag only works on certain texture formats.

Pulled out from the unity documents :

"Read Write Enabled

Select this to enable access to the texture data from scripts (GetPixels, SetPixels and other Texture2D functions). Note however that a copy of the texture data will be made, doubling the amount of memory required for texture asset. Use only if absolutely necessary. This is only valid for uncompressed and DTX compressed textures, other types of compressed textures cannot be read from. Disabled by default."