Loading Images using WWW into a different texture format


We are trying to load images from an external resource. In order to do this, we used WWW class and then create a new Texture2D image. We’re using the sample script from this source: Unity - Scripting API: WWW.LoadImageIntoTexture

renderer.material.mainTexture = new Texture2D(1024, 1024, TextureFormat.PVRTC_RGBA4, false);
while(true) {
    // Start a download of the given URL
    var www = new WWW(url);

    // wait until the download is done
    yield www;

    // assign the downloaded image to the main texture of the object

For some reason, the loaded image is taking up too much memory and it looks like it’s loading an RGBA32 format instead of the PVRTC_RGBA4 format.

Our target platform is iOS and we’re assuming that the texture format is supported.

Our Unity version is 3.5.0.f5


You’re loading png or jpg, so they are not compressed with PVRTC, so you get texture in RGBA32. Unity can create PVRTC textures only on Editor, because that’s where compression code lives. It can not compresses textures in runtime.

Anyway, I think you’re problem is that you have infinite loop. At least I don’t see any break statement.

You can download a pre-compressed texture from the server and upload it to the device texture memory. I’m doing it on Android and posted the code to another question :slight_smile: