[Tip] Faster animationClips loading time

Discussion in 'Scripting' started by n0mad, Feb 17, 2011.

  1. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    Hello,

    just a tip sharing from what I discovered lately :

    Loading animationClips with animation.AddClip() loads faster than putting them directly in the prefab.

    Also, the context of this should be noticed :
    - This is for animated characters with a lot animated bones (40 bones per char, 2 chars on screen)
    - Each character has more than 500 animationclips
    - The only animationClips I'm injecting with AddClip are common animations between characters, not specific ones.
    - Tested on a Galaxy S (Android)

    What I did before :
    1) put all the animationClips in each character prefab, even the ones that are being re-used between different characters
    2) just load the prefab at level initialization

    What I do now :
    1) just put animationClips that could not be shared between characters in the prefabs
    1) Cache all my "universal" animationClips to inject in a AnimationClip[] array at game launch
    2) Each time a character is loaded, I inject it these animationClips with a simple foreach() + AddClip


    Loading time of a full level on a Galaxy S before : 30+ seconds
    After : 15 seconds

    (n.b : my FBX keyframes are not yet fully pre-reduced, so it can be even faster after some work)
     
    Last edited: Feb 17, 2011
  2. kimsama

    kimsama

    Member

    Joined:
    Jan 2, 2009
    Messages:
    97
    Why this improves a loading time?

    -Kim
     
  3. n0mad

    n0mad

    Member

    Joined:
    Jan 27, 2009
    Messages:
    3,731
    Hi,

    This is a pretty old thread, I don't know if Unity optimized their animation RebuildInternalState yet, but this still seems to be faster.
    Also, for the second part of the tip : it's better to Resources.load once all the common clips between gameObjects, and then distribute them with AddClip(), rather than loading them multiple times by putting common ones in each prefab.
    You just merge all the prefab common loads with that method.
     
  4. kimsama

    kimsama

    Member

    Joined:
    Jan 2, 2009
    Messages:
    97
    Thank you for the answer.