- Home /
[ANDROID] Downloading large (4000x4000) textures causes a lot of memory consumption.
So, we're developing a game where we need to download for each game a certain gif. We have split these gifs into spritesheets and they are stored in our database, which we can access through the Rest communicating with Server.
Problem: After I load a spritesheet from the outside, thats about 4000x4000 pixels, the game eats like 100MB of RAM, which is a problem here. Here is a snippet of my code:
private IEnumerator LoadImageFromURL(_AnimatedSprite a)
{
Debug.Log("Checking url");
WWW www;
if(a.HasThumbnail)
{
www = new WWW(a.URL);
}
else
{
www = new WWW(a.URLThumnail);
}
Debug.Log("Started downloading");
yield return www;
if (www.error != null)
{
Debug.Log("Error!");
Switcher.mb.showMessage(MessageBox.MessageType.negative, www.error);
a.Loaded = true;
running = false;
}
else
{
if (!a.HasThumbnail)
{
www.LoadImageIntoTexture(a.Thumbnail);
// a.Thumbnail.LoadImage(www.bytes);
// a.Thumbnail.Compress(false);
a.HasThumbnail = true;
}
else
{
www.LoadImageIntoTexture(a.SpriteSheet);
// a.SpriteSheet.LoadImage(www.bytes);
// a.SpriteSheet.Compress(true);
a.Loaded = true;
}
Texture2D.Destroy(www.texture);
Texture2D.Destroy(www.textureNonReadable);
Resources.UnloadUnusedAssets();
}
running = false;
www.Dispose();
www = null;
string s = a.HasThumbnail ? "animation" : "thumbnail";
Debug.Log("Finished downloading " + s);
}
Any help is appreciated. Thanks!
Answer by Bunny83 · Mar 25, 2014 at 12:53 AM
As you can read here and on other pages in the docs Unity only supports a few compressed texture formats. However Android devices only support a small subset of these and if the hardware doesn't support a particular hardware compression it's loaded as uncomressed texture.
If you do the math:
4000 * 4000 * 4 == 64MB
If you also use mipmapping it's even more.
ps: Are you actually sure that the gif image is loading? In the past and according to the docs only JPG and PNG images can be loaded at runtime via WWW. Maybe that has been changed. Anyways you should also read this page carefully to understand when a loaded texture is actually hardward compressed and when not
Also keep in $$anonymous$$d that textures that are r/w enabled take even more memory (if I'm remembering correctly).
Uhm, actually I'm downloading a .png spritesheet generated from the gif. That's what I meant, but probably expressed myself wrong.
Well, ok that makes a bit more sense. What TextureFormat does the texture has before you used LoadImageIntoTexture? because that's the main guide what format the texture will have once loaded. $$anonymous$$ake sure you created a texture with the desired TextureFormat before you call LoadImageIntoTexture
I love you bunny. I set the TextureFormat to DXT1 BEFORE loading it and now it eats doable memory :)
Answer by mavii_ege · Mar 24, 2014 at 11:03 PM
Try to compress images and cut to pieces like part 1,2,3
Cutting it to pieces won't help. You still load a bunch of images combined gives the same memory consumption. Tried to compress it with pngout, didn't help.
Hmm I'm just kinda curious about your project. Is there a reason why you have them downloading these images from the server?
$$anonymous$$obile platforms seem to be TERRIBLE with texture compression so this problem does not really surprise me when combined with communicating with the server as well.
If you are just doing 1 sprite at a time for the user, it may be better to have a small file for each image because right now it sounds like they are loading the entire 4000x4000 image even when they are only retrieving one?
What you are doing is way beyond any of my experience so there's a very high chance I could be totally wrong, but that's my initial thoughts.
Uhm, the app is basicly a rating system. User downloads an animation from server and then rates it. He only needs 5 animations per game. But with just one animation downloaded the memory goes wild. (64$$anonymous$$B)
Answer by DeveshPandey · Mar 31, 2018 at 08:42 PM
Here is a nice plugin, its very easy to use. You can download any small or big file from the web. Must see this plugin
https://www.assetstore.unity3d.com/#!/content/92128?aid=1101l34jr
For more details visit this blog
Your answer
![](https://koobas.hobune.stream/wayback/20220613141058im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Spritesheet animation shake/jitter/wobble problem on android. 1 Answer
Animation not allign properly 0 Answers
Need help with script 1 Answer
add animation frames to existing spritesheet with animations? 0 Answers
Why is my game lagging when I use Unity's animator to change color of a image in Unity3D? 0 Answers