Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Streaming AnimationClip and overriding the mecanim AnimatorController

Discussion in 'Animation' started by DoomSamurai, Apr 17, 2014.

  1. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    HI all!

    I found a few posts explaining how to override a AnimatorController clip with the AnimatorOverrideController but I still seem to have issues with playing the actual clip that i'm overriding with.

    I'm streaming AnimationClips with an AssetBundle. Here's what my code looks like right now:

    Code (csharp):
    1.  
    2. public AnimationClip ANIMATIONCLIP;
    3.  
    4. void SetNewAnimation(WWW w)
    5.     {      
    6.         foreach (Object item in w.assetBundle.LoadAll())
    7.         {
    8.             if (item.name == "idle_shakes") ANIMATIONCLIP = (AnimationClip)item;
    9.         }
    10.  
    11.         RuntimeAnimatorController myController = animator.runtimeAnimatorController;
    12.         AnimatorOverrideController animatorOverride = new AnimatorOverrideController();
    13.         animatorOverride.runtimeAnimatorController = myController;
    14.        
    15.         animatorOverride["oldclip"] = ANIMATIONCLIP;
    16.  
    17.         animator.runtimeAnimatorController = animatorOverride;
    18.  
    19.     }

    This seems to work as far as loading the animation from the bundle and setting the animation clip to override the old clip. When I get to actually playing the animation (the animation is played from the Any State node when I set a trigger), my character freezes. When I trigger another animation state it transitions to the new animation correctly. Only the overriden animation causes this problem. If I set the same animation directly in my controller and don't override anything, it works fine. Is there something I'm not aware of like overriding clips need to have the same length or something like that?
     
  2. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    I changed my AssetBundle to contain not only the AnimationClip but the actual fbx and now it works. I guess it is a requirement for mecanim that the animation import parameters be present in the AssetBundle for the override to work ?
     
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    You drag in the FBX, but the FBX isn't what's stored in the asset bundle - it's the imported animation data derived from that FBX. (Generally speaking, storage file formats and runtime data formats are completely different things. In the Editor we play with the former, but the runtime uses everything as the latter.)

    So to answer your question, short answer "yes", longer answer "it's the animation data you need that you're adding, not the import settings themselves".

    Hope that helps!
     
  4. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    In theory you shouldn't need to add the fbx file too.

    Can you log a bug with a small project that repro this bug, please send me your case number that you should receive with your bug report email notification.

    Thanks
     
  5. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    Sorry I didn't see this post before today, my notifications don't seem to work properly most of the time. I ran some tests and this issue seems to have been fixed. Thank you.

    I have one more question though. Is it possible to define animation states as empty (no animation clip assigned) and populate the state with streamed animation clips at runtime? Right now it seems I have to assign an animation clip to a state and override the animation clip by name with my new animation. What I'd like to do instead is assign a clip at runtime without the need to stream placeholder animation clips in my Animator beforehand.
     
  6. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Unfortunartely, it not possible right now, you can override only clip. Like you said the only way right now it to build your controller with placeholder clips.
     
  7. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    Okay, it's not a huge issue. Thanks!
     
  8. comworm

    comworm

    Joined:
    Aug 13, 2014
    Posts:
    11
    Hi,
    I am spending my whole day to solve same problem as you.

    'Overrided animation clip by AssetBundle doesn't work, but draging actual fbx works without any problem.'

    It seems that you already solved your problem, and can you please answer me how you solved it?

    Thanks in advance.
     
  9. comworm

    comworm

    Joined:
    Aug 13, 2014
    Posts:
    11
    I understand your explain.
    But I am sorry, but would you please explain how to come over the problem?
    How can I load AnimationClip from AssetBundle?

    I duplicated all the AnimationClip from FBX import setting. And then, made AssetBundle with it.
    As long as I know, at this moment when I duplicate them, AnimationClip became runtime data format, didn't it?

    Thanks in advance.
     
    Last edited: Aug 13, 2014
  10. comworm

    comworm

    Joined:
    Aug 13, 2014
    Posts:
    11
    Wow!! I finally solved my problem.
    My problem was that I was initiating AnimationClip after loading it, which need to be loaded only.
     
    angrypenguin likes this.
  11. nonehill

    nonehill

    Joined:
    Oct 29, 2014
    Posts:
    7