Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mecanims memory requirements make it unusable for mobile games

Discussion in 'Editor & General Support' started by MadDave, Aug 8, 2013.

  1. MadDave

    MadDave

    Joined:
    Jul 9, 2012
    Posts:
    6
    When Mecanim was released we were pretty excited and soon switched to the new system. Now, several months later, we deeply regret that decision. We will have to switch back to the legacy system, scrapping weeks of work with even more weeks ahead of us. Here is why:

    Our game is an MMO with lots of animations and lots of characters running around. It needs to run on the iPad 3 (among other platforms). A few days ago we ran into memory problems on the iPad. Thanks to Unitys new memory profiler (which is very cool!) we quickly identified the problems. To our great surprise, the Mecanim Animator component of every single character needed almost 7 MB (!!) or RAM. That means that 15 characters (which is not a lot for a game like ours) alone eat > 100 MB, crashing the iPad.

    We could not quite believe it and started digging around, comparing our project to Unitys Mecanim samples. We were clearly doing something wrong. Turns out we did not. Here is what we found:
    • Every single State in an AnimationController needs ~11KB. (Per Animator INSTANCE, for whatever reason!)
    • Every single Animation in a BlendTree needs ~15KB. (Again, per Animator instance.)
    • This is true even if you use the same animations multiple times. 10 entries in the blend tree, even if it’s really just two different animations, amount to ~150KB.
    • A second layer roughly doubles the memory requirement of the Animator (as if you copied all states and blend trees from the other layer.)

    And that is the ugly truth. We have ~80 character animations, 2 layers, 7 blend trees. Amounts to 7 MB per character instance. Bye bye, iPad.

    The whole thing is just crazy. Even if we accept that states and blend trees need meta data – why does all of that data exist per instance?

    tl;dr: Mecanim is not production ready. It may work for samples and student projects, but it does not for real world mobile games.

    Dear Unity Team: Is this something you are working on? Is this fixable in the near future or do we really need to abandon Mecanim alltogether? (And please feel free to contact us for more information!)
     
  2. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I don't know exactly what the numbers are for which versions of Unity. But those numbers seems much too high. I know the actual data contained in the Animation Controllers, Animations and Avatars are mere assets. Certainly there is book keeping on top, but 11k per state doesn't sound right to me. Actually there should be no per state cost as far as I can see.

    I can only recommend you file a bug and attach a project that will reproduce the memory usage. It doesn't have to be the full mmo, just any project that clearly shows this radical memory growth you're describing.

    Yes, we're constantly improving on Mecanim and is still making significant improvements on it. Since its initial development the team has only grown.
     
  3. MadDave

    MadDave

    Joined:
    Jul 9, 2012
    Posts:
    6
    Thanks for the swift reply. I agree that these numbers are WAY too high. The overhead per instance should certainly be only a few KB, not MB.

    I have filed a bug report, complete with example. (Ticket 556626)

    The problem is acutually easy to reproduce using any existing mecanim project. We used the GDC 2013 sample for sake of simplicity.

    - disable the StartRecord() and StopRecord() functions in Recorder.cs. They eat a lot of memory and are not needed in this example.

    Start the game, collect the popsicle, wait for the bears to spawn. Now open the memory profiler and check the "Scene Memory" tab. We are interested in the Animators of the bears.

    Observe that even in the unmodified sample, every NPC Animator uses 122.7KB (already quite high if you ask me).

    Stop the game. Now edit the Animator controller of the NPC and add a blend tree. Add the idle anim 10x to the blend tree. It does not have to be connected or anything. Start the game, repeat the measurement like above. Every bear now uses 175.7KB.
    Copy the blend tree 9x. Memory consomption is now 0.6MB per bear.
    Add 20 empty states, again no need to connect anything. Memory is now at 0.7MB per bear. You get the idea.

    I would like to stress again that this problem is very real. We have 80 animations, two layers and a few blend trees. The animator of our character currently needs 7MB and we need to do 20-30 characters (>200MB) ... on an iPad :(

    I would really appreciate any info you can give me. If this is not fixed soon, we will have to write our own animation system on top of the legacy system.

    $Memory.jpg
     
  4. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Hi.

    So the reason why the Animator instances use that much memory is that we create some acceleration structure, per clip, that allows us to evaluate really fast at runtime.

    Can we do better ? yes. And that is certainly one goal of Mecanim in Unity's next version ( 4.3 ). We have already seen 2x less memory used by Animator instances in some cases and we are still working on improving it.

    Until we release that version (which hopefully will fix your issues), I can say that 2D BlendTrees use more memory than 1D blendTrees so maybe thats a start.

    pp
     
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    Why is that a per-Animator-instance cost, instead of a per-AnimationController cost?
     
  6. MadDave

    MadDave

    Joined:
    Jul 9, 2012
    Posts:
    6
    That is an excellent question! You need to create certain lookup structures, no doubt about that. But you need that once per clip/skeleton-pair, certainly not per Animator instance and certainly not multiple times for identical clips in a blend tree.

    Quite frankly, "2x less memory used by Animator instances in some cases" is not gonna cut it.

    We have 100 - 200 MB memory usage for Animators. Total animation data size is ~7 MB. "Acceleration structure" seems to be a bit of an understatement here.

    Idea: if you let us take a look at the code we can help to improve it. We have several experienced engine devs on the team (including myself), so this is a serious offer. If you guys cannot solve this soon we'll have to look for an alternative anyway.
     
  7. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Its per instance because we keep a cache of last evaluated keyframes coefficients (to put it very simple..)

    We are currently putting a lot of effort on memory footprint improvement, we will manage to make it really smaller.

    stay tuned!

    pp
     
  8. Bercilak

    Bercilak

    Joined:
    Aug 8, 2013
    Posts:
    1
    Hi pierrepaul,

    even if you make it faster by factor 2, this does not change anything. To be en pair with the compeititon you have to make it faster by factor 100, just to make clear how far you are away from fixing this issue.

    So overall it stands that Mecanim is not useful for larger iOS productions and honestly you should have a warning somewhere making developers aware of this massive memory usage!

    To me it seems as if you released a product which still belongs into alpha/beta testing. However the offer still stands that we can have a look at your problems. We have a few very experienced developers here working on a larger project: https://www.facebook.com/albiononline

    We are also fine with signing any NDA's or similar, we just want this problem to be fixed asap.

    Kind regards,
    Stefan
     
  9. CyberDog

    CyberDog

    Joined:
    Oct 19, 2013
    Posts:
    12
    Hi All,

    Very interesting thread.Is there any progress on "mecanim for mobile" subject?

    Regards,
    Patryk
     
  10. tonyclifton

    tonyclifton

    Joined:
    Nov 23, 2009
    Posts:
    13
    I just subscribed to this thread. I'd like to know more, too. We are exclusively working on mobile games.
     
  11. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    We have made great strides in memory / performance in 4.3.

    The optimization can vary greatly from project to project but we have seen performance gain of 2x.

    As for memory optimization ( which is very project dependent, based on number of blendTrees, states etc..) we a test scene we had we went from 6megs -> 500k

    pp
     
  12. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,172
    Excellent news! Looking forward to the fixes and new enhancements. Mecanim has really improved my workflow.
     
  13. Chrisbe

    Chrisbe

    Joined:
    Oct 9, 2013
    Posts:
    1
    Are there plans for more memory optimizations, specifically around 2D blend trees? Currently, we are @ 1.7MB/player and we have 30 players. This is due to a large 2D blend tree we have for locomotion. Unfortunately there is little that we can remove from it and maintain the desired functionality.

    Thanks,
    Chris
     
  14. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Hi all.

    There as being tons of memory optmizations in the last releases ( 4.3, 5.0, 5.2).

    Are you guys still having those very high memory overhead when using Mecanim ?

    thanks!
     
  15. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115
    Bump.
     
  16. joe-il-rustico

    joe-il-rustico

    Joined:
    Jan 10, 2013
    Posts:
    2
    Has there been any development on the subject?
    Any developers willing to share recent experiences with mecanim for mobile?