Create and manipulate Animator/Animation at runtime

Hi, I’m working on a project that must handle models loaded from AssetBundles (on a server), but these bundles won’t be created by us, that is we don’t have absolute control over those models nor their animations. However, we need to manipulate animations by our logic (when to play, when to stop, when to loop) rather than predefined Animators’ logic. After doing some research and testing, I’ve figured out a solution, but I still don’t have any idea how to do it:

  1. Getting animation data from the existing AnimatorController in the bundle or on the model prefab.
  2. Using that data to create a very simple Animator with separated states, no parameter, no blend, whatsoever.
  3. Remove the old AnimatorController then attach the new one to the model.

As far as I know, there is no way to do this at runtime. But I still post the question here, hope to hear some advices from anyone.

(Another factor contributes to the problem: we don’t know anything about the Animator’s state names. There is no way in Unity to get those names at runtime. Besides, we cannot rely on nor force the person who makes and uploads his AssetBundles to our server to provide us the correct list of state names for each model.)

PS: I’ve thought of another solution that will convert AnimationClips gotten from runtimeAnimatorController to legacy Animations, but it seems doesn’t work either or I just don’t know the proper way to make it.

Hi,

you should check out our Playable API

It basically the same tech used in an AnimatorController but it give you more flexibility at runtime to customize your blending graph. You have a few different animation playable available for you:

AnimationClipPlayable
AnimationMixerPlayable
AnimationLayerMixerPlayable

1 Like

Hi, could you please take a look at this thread?
https://discussions.unity.com/t/704071