Search Unity

How can I find what is referencing an AnimationClip?

Discussion in 'Editor & General Support' started by Dreamwriter, Nov 3, 2015.

  1. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I've searched memory using FindObjectsOfTypeAll and found an AnimationClip that shouldn't be there. How can I figure out what is referencing that clip?
     
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    Well... a quick and dirty way would be just to move it out of your project and hit play. ;) Look and see what is broken.
     
  3. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Unfortunately, nothing at all is playing the animations, so removing them from the project will do nothing. But something is still loading them into memory, some script must be referencing them somewhere in its inspector variables. We're trying to cut the memory usage down (we have around 85MB worth of animations in memory, we probably only need around 40-50 MB on any specific level)...but removing the unused clips from the Animation isn't removing them from memory.

    So using FindObjectsOfTypeAll I have a pointer to the bad animation clips, but I don't know how I can find what is holding onto them - as far as I know there isn't a link to an Animation that holds the clip or to a holding GameObject or anything.
     
    Last edited: Nov 4, 2015
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    This is a long shot, but in some cases shaders reference images that were swapped in editor (I think it was related to undos). It might be the case with animators as well, not sure. You could try doing a refresh on your project to rebuild the metas. You could also try clearing the contents your library folder. Just to make sure that it's not some old reference that is hanging on.


    Also, do you recognize the animation? Is it something you created, and not generated by the ui or something else?
     
  5. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Oh, it's a whole bunch of animation clips that we created for characters in the game. We recently needed to free up memory, so we went into each level (scene) in the game and manually deleted the animation clips from the animations on those characters, the ones that weren't needed on those specific levels (for example, a slipping-on-ice animation on a level with no ice).

    But those animation clips are still in memory when the scene gets loaded, even if that scene is the first one loaded when the game starts, which means something in the scene is still referencing them. And I'm having a heck of a time figuring out what it is.
     
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    Out of curiosity, how exactly to those clips get into the project? Are they part of an fbx? If they are in the fbx, then they will still be loaded into memory when you load the fbx. (even if you never reference them). We discovered that the hard way. If that is the case, there is a couple of ways around that.
     
  7. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    More information - it's something to do with turning a model into a prefab. I take the source model, drag it into an empty GameObject in the scene. By default it has an Animation component with one animation on it. I add 3 more animations, run the game: 4 animations are in memory. I remove one (highlight it in the Animations table, hit delete, so it is replaced with None), run the game, 3 animations are in memory. So far so good, so I put the 4th animation back (and make sure it is in memory).

    I now drag my GameObject into the Project to turn it into a Prefab. Now if I go to the GameObject in the scene and delete an animation from the table, running the game shows there are still 4 animations in memory. I highlight another and delete it, still 4 animations in memory - animations will no longer get deleted now that the model is part of a prefab; they aren't in the Animations table but they are in memory.

    If I remove animations from the prefab in the Project, only then does it removes them from memory
     
    Last edited: Nov 10, 2015
  8. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,350
    A couple of notes:

    1. Resources.FindObjectsOfTypeAll will return any loaded objects, including ones that are loaded in the editor, but not by the scene.
    2. You can use the profiler, specifically the "Memory" track. Switch it to "detailed" view and capture a snapshot (there's a button for that). You get a nice drilldown into memory, including objects and what references them. You may be able to find your object that way.
     
  9. mizrahi.diego

    mizrahi.diego

    Joined:
    Jul 3, 2014
    Posts:
    1
    Can you figure out what is the problem ?!

    I have the same problema and i dont know what else to try.
     
unityunity