Dynamic texture resizing or switching between texture sets of different sizes at runtime

Just wondering if there is any native function in Unity to dynamically resize textures at runtime? Alternatively a simple way to swap out texture assets at runtime?

I need to be able to provide a single build that can work for someone with say 128mb, 256 or the target 512mb+. So depending upon the gpu ram, one of 3 different texture sizes will be used, however I certainly don't want to include all 3 versions of each texture in a single build. Essentially its just like how commercial games run, in which the textures are dynamically/pre-created in scaled down versions, so the game can easily run on different configurations of available ram.

For example back in good old Director I had two methods available. The first was to use a function called 'scaledown' which simply halved the size each time it was called on a texture. The second option was to store all the texture images in a single external cast library and then make two versions, one full size, the other all half size. Then at runtime you could just load the appropriate castlibrary. Actually there is a third, which would be to have all texture images imported as 'linked' and simply change the pathname at runtime.

I can't find a similar function to 'scaledown' and suspect that since Unity doesn't appear to include the source images in a build, it wouldn't be possible?

I guess I could import the textures at runtime, but not sure if I lose some of the benefits of having them in the editor, such as setting values in the inspector?

AssetBundles may work for this, though i'm still looking into them so not sure of their requirements or restrictions.

So i'm wondering how do other developers approach this situation?

If you let unity calculate mipmaps, you can just use GetPixels(mipmapLevel) and it'll give you pixels back relating to a texture which is the next power of two down for each level

That way you can easily make a new texture from those pixels


You could do something like this to half the original texture, as long as the texture is readable:

Texture2D temp = new Texture2D(originalTexture.width / 2, originalTexture.height / 2);
byte[] png = temp.EncodeToPng();

It's a little bit of a roundabout method, but you could wrap it in a function and make it half any texture

Stumbled upon the answer (at least it will do for now) in Edit->Project Settings->Quality inspector, where you can set the 'Texture Quality' to 'full res', 'half-res' etc, with each Quality mode having its own setting.

Yet to test it fully, but should suffice for my needs.