Setting isReadable for a procedurally created texture asset

Hello all.

I’m having trouble discovering how to set the isReadable flag when creating a procedural asset.(mesh or texture)

In the following code, TextureImporter is null.

    		AssetDatabase.CreateAsset(nodeDb.Texture.GetTexture(), Config.TexturesDirectory + "/Texture" + nodeDb.NodeIndex + ".asset");
    		TextureImporter texImporter = AssetImporter.GetAtPath(Config.TexturesDirectory + "/Texture" + nodeDb.NodeIndex + ".asset") as TextureImporter;

If I can’t get TextureImporter, how do I do this? An object is returned but is of (undocumented) type NativeFormatImporter which has an almost completely bare interface.

I built an application that extracts images from a database, compresses them(native to iOS) and saves them directly to the assets directory. When I load them onto the device it appears I’m using way(~2x) too much texture memory - like a copy in memory and for VRAM (yes I understand that VRAM is shared on iOS devices).

This is totally defeating my entire memory saving strategy and really quite bad for me. I just assumed I’d be able to retrieve a TextureImporter.

Perhaps something (hacky) could be done with NativeTexture pointers???

Can anyone please help? It appears a few have been frustrated when building procedural assets. Why not have the read/write flag in Texture? Please?

Any help much appreciated.


I know this is a very old topic, but I think I’ve discovered a solution.

I’m not sure when it was added, but in the current version of Unity (5.4), Texture2D.Apply now takes a second argument, “makeNoLongerReadable”. With this set, the copy of the texture in system memory will be released.

Now, you can do this on procedural Texture2Ds, Texture3Ds, and Texture2DArrays.

myTexture.Apply(true,true); // will generate mip-maps and free copy