Hopefully I’m just missing something obvious.
I’m using an editor script to create a few texture arrays and they’re left readable at the end so at runtime they’re taking up system and video memory. I only seem to be able to change isReadable on texture arrays by setting the Inspector to Debug and manually changing it.
There doesn’t seem to be a “TextureArrayImporter” and, perhaps not surprisingly, this doesn’t work:
var textureImporter = (TextureImporter) AssetImporter.GetAtPath(textureArrayPath);
Nor does attempting reflection schenanigans. (Also unsurprising!)
So, two questions:
- Is there a way to change isReadable for Texture2DArray via a script?
- If not, is there a technical reason? The texture arrays seem to work in editor/windows/recent android/iOS13 with isReadable set to false.
Cheers!
Najati
Didja check the documentation?
I quote,
“Currently in Unity texture arrays do not have an import pipeline for them, and must be created from code, either at runtime or in editor scripts.”
So that’s why it doesn’t work, but beyond that I cannot comment as I have not had need to use this yet.
Further, reading this:
https://docs.unity3d.com/ScriptReference/Texture2D-isReadable.html
again I quote,
“For a dynamic Texture created from script, always returns true”
I think you need to make a texture importer for the actual textures, and mark them how you want there, then assign them to the array? Just a guess.
Thanks for the reply!
The readability of the textures in the arrays doesn’t have an affect on the readability of the texture array itself. It’s a wholly separate assets without any association to the textures you might copy into it.
The lack of an import pipeline seems to be part of the issue, but there’s enough support for them in Unity that they seem to work with my game on various devices and you can set isReadable on the asset in the debug properties.
My first question above is a matter of convenience. I’d like to make sure the textures that are generated by my editor scripts are set to isReadable=false without having to remember it, so I don’t run into the double memory issue.
The second question is a matter of functionality. Is there something about the way that Unity treats the arrays that requires they be readable on certain platforms or for performance, etc. This would surprise me.
I’m also curious about this issue being so hard to find information about. It makes me think very view people are actually using TextureArrays? Or a lot of people are using them, but are suffering from have a system-side copy of their array without knowing about it?
Or maybe it’s just generally well understood enough that folk just enable the debug properties to flip the setting every time they update an array. That seems unlikely to me.
1 Like