Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GetCurrentAnimationClipState() allocates memory ?

Discussion in 'Animation' started by RamzaB, Mar 20, 2015.

  1. RamzaB

    RamzaB

    Joined:
    Nov 4, 2012
    Posts:
    42
    GetCurrentAnimationClipState() seems to be allocating memory everytime it is called.
    In my program, I need to call this function everytime during Update(), so the memory allocation is done every frame.

    Is it possible to avoid this ?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    No because a state can be a blend tree which can contains many clip so we need to create an array of clip info in this case
     
  3. RamzaB

    RamzaB

    Joined:
    Nov 4, 2012
    Posts:
    42
    I think there are two simple options here:
    1. Unity can create the array of clip info once, and then reuse it for subsequent calls.
    2. We can create the array on the game side once, and then pass it to Unity. So if Unity could provide GetCurrentAnimationClipState() which accepts an array, that would be great.

    Or maybe there are reasons that the above options aren't feasible ?
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Not sure for this one because we would need to allocate the memory for the worst case scenario blend tree, in some case we saw some client with direct blend tree with more than 100 clips. That would mean that we would allocate an array of 100 clip info only to support the worst case scenario.

    I think in such case since you want fine control over the memory allocation we should go for the options 2.
     
  5. RamzaB

    RamzaB

    Joined:
    Nov 4, 2012
    Posts:
    42
    100 clips ! Wow, they must have amazing animations there ;)

    Jokes aside, yes, option 2 will do just fine, so, erm, when can we expect to get this ?
     
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    I will try to get this improvement in 5.1, otherwise it will be 5.2
     
  7. RamzaB

    RamzaB

    Joined:
    Nov 4, 2012
    Posts:
    42
    Okay.
    I guess it is still too early to announce when 5.1 or 5.2 is going to be released ?
    I hope sometime this year though.
     
  8. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    There is no ETA yet sorry