I am loading an FBX file at runtime using “TriLib2”.
I am trying to create an AnimatorController using the loaded AnimationClip.
var animation = assetLoaderContext.RootGameObject.GetComponent<Animation>();
List<AnimationClip> clips = animation.GetAllAnimationClips();
var animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPathWithClip( UnityEngine.Application.temporaryCachePath, clips[0] );
_animator.runtimeAnimatorController = (RuntimeAnimatorController)animatorController;
_animator.enabled = false;
However, this method does not allow it to be created at runtime, so the animation cannot be played.
When loading an FBX file with only animation, the avatar meshes displayed are out of sync and appear disjointed,
so I would like to control them with an AnimatorController, but how can I create an AnimatorController at runtime?
Thank you in advance.
You can’t.
Animator Controllers and non-Legacy Animation Clips can’t be created or modified at runtime. Unity simply doesn’t support it.
That’s why TriLib is creating a legacy Animation component and legacy animations instead of an Animator component and Animator Controller.
The only way to load Animator Controllers or non-Legacy Animation Clips that weren’t included in your build is to use Asset Bundles, which can only be exported from the Unity Editor (i.e. you can’t just import an FBX).
In that case, what should I do if I want to reflect the animation of a Humanoid avatar that uses a different avatar?
I was able to link it to the AnimationClip by changing the avatar file path, but I haven’t been able to control the MeshRenderer.
Is there any other way to do this?
Your only options as far as I know are to either make sure your characters use the same rig so you can use legacy animations without needing to retarget them or to use asset bundles for loading new stuff at runtime.
Thank you.
We will proceed with the issue using the same Rig.