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

Bug AssetBundle.Unload and AnimationClip.AddClip

Discussion in 'Asset Bundles' started by BIGcheese89, May 1, 2021.

  1. BIGcheese89

    BIGcheese89

    Joined:
    Jun 4, 2013
    Posts:
    4
    Hi all,

    Think this is a bug as the behaviour is different to that of a texture reference. Or the documentation needs updating to better describe what AddClip does.

    The hope would be that the following code sets the clip (as viewed in the inspector) to null:
    Code (CSharp):
    1. AssetBundle assetBundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(Application.streamingAssetsPath, "assetBundle"));
    2. AnimationClip animationClip = assetBundle.LoadAsset<AnimationClip>("animationClip");
    3. gameObject.AddComponent<Animation>().AddClip(animationClip, "addClip");
    4. //AnimationClip.DestroyImmediate(animationClip, true);
    5. assetBundle.Unload(true);
    upload_2021-5-1_18-36-0.png

    Destroy immediate did not help either. My only thought is its a bug, or it instantiates the clip underneath (a bit like Renderer.materials does). But that can't be true... because a game with lots of assets would have huge memory footprints.

    Thanks in advance!

    EDIT: Also interestingly, set the Animation array to 0 and look at the profiler, AnimationClip is still in memory. Will go only when you remove the Animation component.
     
    Last edited: May 3, 2021