Search Unity

Animation size optimization, GameObject animation vs skinned mesh 2D

Discussion in 'Animation' started by JonPQ, Jul 7, 2022.

  1. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    So we've been trying out the new 2D-Anim package.
    I have a test object... a cute squid with 3 tentacles, 3 eyes. about 30 bones in all.

    V1
    First off we built this as multiple sprites, one per bone segment in the tentacles ( about 6 per) plus the head, eyes etc... Then animated a 2 second idle.. animating the gameobject transforms for position rotation and scale directly... the .anm file is ~250kb. ( it is 25+ game objects, each with a SpriteRenderer )

    V2
    Next we use 2D Anim system... just a single sprite image of the same squid... with the tentacles separated from the body. Meshed it in sprite editor with a single mesh, 4 separate UV areas.... head and 3 tentacles.
    made same length animation. same number of bones. ( only 20 gameObjects/bones. only 4 of them have sprite renderers ) same 2 second idle animation.

    V2 looks a little nicer, and has less overdraw ( V1 has a lot of over-lapping sprites )
    V2 is slightly slower on animation update, but only a little.
    BUT. V1 file size is 250KB and V2 is a 1.1MB .anm file. WHY ? why is the skinned version 4x bigger. it makes no sense.
    The number of vertices is low... <20 per tentacle and 6 for the head
    both .anm files are created in unity ( not from fbx) ... same number of bones, same animation, made by same animator artist.

    The only file size difference I could guess at should be a small list of vertices per bone, for bone weights. but this would not make the file 4x larger. ( maybe a few kb bigger )

    Is there some inherent problematic way it stores animation data for the 2D skinned system that makes the file much larger ?
    Looking at the .anm file text data, there just seems to be a lot of curves information.
    But looking at the animation clips in unity.. the first animation actually looks more dense due to having more gameobjects, but the saved file is much smaller.

    Does anyone have any insight into this please ?
     
    Last edited: Jul 7, 2022
  2. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    comparing the 2 files... the smaller file looks like for each curve, it stores an entry maube 4 to 10 times per curve.. maybe matching each key frame in the animation.
    For the large file.... it looks like for each curve it has stored an entry for every single frame, regardless if there is a key frame there or not. consistently 1/30th of a second apart... hence why it is much larger... I don;t know why it does this... I can't find any controls to change this behavior... it makes me sad though :'( haha

    what can cause this? is it just difference between animating gameobjects, and meshes ? or any unity quality settings ?

    I wonder what would happen if I wrote a script to remove every second entry ( apart from first and last key ) or remove all curve entries that are not on a keyframe.... hrmmm
     
    Last edited: Jul 8, 2022
  3. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    [ I'm using unity 2020.3.3 ]
    I think unity decides how to compressed based on some internal rules... these two animation files... animated by same animator... gameobject animation, vs skinned-2D. same animation just different styles... look the same. but one has animation curve info per frame, and one, per Key. makes a huge difference in file size, but not in perceivable animation quality. This should be under dev's control... not automatic. :(

    does anyone have any ideas please ?
    left file [skinned 2D sprite] ( "time" increments once per frame. 3 'keys' = 3/30s )
    right file [gameObject hierarchy of sprites for bones] ( "time increments once per key-frame, 3 'key frames' = 1s ) )

    upload_2022-7-8_12-10-13.png
     
    Last edited: Jul 9, 2022