Search Unity

How Much is too much for a 2D game ? (Terminated due to memory issue)

Discussion in 'iOS and tvOS' started by Aladine, Nov 7, 2016.

  1. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    Hello everyone,

    So i'm working on this little game here :



    10 months ago we had a memory issue on iOS only, that we then solved it by stop using the default unity 2D Animation system and instead use GAF the problem is this (quote from my reddit post 10 months ago)

    Now we're getting some issues with GAF, and while waiting for their support, i would really like to get this mystery solved,

    Why can't the iPhone5 handle "big" animations ?
    i tried not to use GAF and have our animations been played by the unity animator and all we got is that memory error.

    For the current scene causing the crashes we have 11 animations with each of them is a PNG that is between ~1.5MB and 2.5MB, all of them are 2048x2048, and they have around 20 frames with each frame being 512x512.

    Is that Alot for iOS to handle ?

    Knowing that the games works perfectly on my galaxy S5.

    PS
    I am by no mean an iOS expert, neither is my friend, the only info that i can give now after few research is taht "Zombies" are disabled (never heard of these before today lol)

    Any help please ? is there anything that we can do to "debug" this issue ?


    Thank you
     
    Last edited: Nov 7, 2016
  2. SimteractiveDev

    SimteractiveDev

    Joined:
    Jul 9, 2014
    Posts:
    97
    Well the Galaxy S5 has 2GB of ram, while iPhone 5 only has 1GB, so you have twice as much ram on the Galaxy. The S3 only has 1GB of ram, but iOS and Android behave differently and have different memory thresholds for terminating apps.

    It's hard to tell based on your description of your animations, but what needs to be loaded in memory for your animations? Is it a 2048 x 2048 texture per animation or 20 512 x 512 textures per animation? If it's 2048 x 2048, that means you are using ~ 176MB for all 11 animations (assuming not compressed). If it's 512 x 512, then you are using ~220MB for all 11 animations. That should be fine on an iPhone 5, but if you have more stuff loaded, then it could be pushing you over the edge. A quick fix would be just compress the textures.

    I'd recommend checking your memory usage in the Unity Profiler and Xcode. The Unity Profiler can show you what is using memory if you take a memory snapshot. Then you can work from there to determine what you need to do to bring the memory usage down (e.g. compress the textures, do you need all 11 loaded at the same time etc).
     
  3. Kossuranta

    Kossuranta

    Joined:
    Jul 12, 2013
    Posts:
    2
    I think that all of the iPhones before 6s have only 1GB or RAM and some of it is already in use so you could just simply be running out of memory. Is your images for the frames compressed? Also you could think that do you really need 512x512 sized images. Depends where you use it, but it kinda sounds bigger than what the actual size would be on screen.

    P.s. Even the resolution of iPhone 7 is only 750 x 1334. 512x512 image would be around 25% of the screen.
     
  4. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195

    We have 11 2048x2048 .PNG files, their texture types is Sprite, the mode is Multiple, and they had 16 512x512 "sub-image" , will try Compressing it, but that will make the colors look a bit dull and the edges blurry...
     
  5. r-pedra

    r-pedra

    Joined:
    Dec 4, 2015
    Posts:
    104
    That's really really big. My advice is that instead compressing it, keep it truecolor but resize your atlas to make it at least 2 times tinier.
    I don't if this chest is supposed to be displayed really big on the screen but if it's only an element of a level, you should really consider reducing it's size.
    It's already 176MB only for animated textures, even if you make it run on the device, I doubt your users will be able to download the game with mobile data.

    To see the amount of textures you have in your game, you can simply build the game and in the Unity console, click on the 3 bars and select "Open Editor Log", scroll up in the file it opens and you should find a summary of all the assets in your game and their size, sorted by size and by type.

    If you are targeting iOS and you use Unity 5.4, you should try the new ASTC compression that Metal devices can use, there are really good results with this compression.

    You should also try that https://bitbucket.org/Unity-Technologies/memoryprofiler
    If the game launch, just run this thing and it will tell you what is in your memory at this moment. if you see duplicates, it could explain the problem. (If can't even run the game, maybe try to strip your ressources to test only with a low amount of textures to see what append with this texture.

    What we also noticed in our game is that when a scene have a link to a prefab that contains a Texture, it loads the texture in Memory. So if at the beginning of the game you have a scene that links to almost all prefab, it will load everything to the device memory. What we made to avoid this is that we used AssetBundles to load only relevant Textures and other objects into memory only when we know we will need them.
    For exemple, if you have a prefab linked with your chest texture, somewhere in your scene, and you are in the menu, you don't need the chest texture, but it is already in memory an this is bad.
     
  6. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    I just ask my friend to give me his iOS build log, and you're totally right ....

    So yeah we are going to change all the textures in the game from TrueColor to compressed

    "If you are targeting iOS and you use Unity 5.4, you should try the new ASTC compression that Metal devicescan use"

    where is that ASTC compression option ?
     
  7. r-pedra

    r-pedra

    Joined:
    Dec 4, 2015
    Posts:
    104
    You definitely have a LOOOOOOOOOOOOT of textures.

    About ASTC, with Unity 5.4.2p1 (this is the version we use, maybe this is available to some previous releases), if you go to a texture and then select the iPhone settings, check "Override for iPhone" and in Format list you should find ASTC. This compression is splitting your textures in squares, compressing each square and reassembling the texture. So the bigger square you select, the bigger compression is, the uglier the texture is. 6x6 is generally a good option
     
    Aladine likes this.
  8. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    thanks mate