Load AnimatorController from AssetBundle as RuntimeAnimatorController.
Hi,
I'm using Unity 5.5.0p3 on Windows 7 and this is how I currently try to dynamically load AnimatorControllers from an AssetBundle:
RuntimeAnimatorController tmpController = assetBundle.LoadAsset("MyAnimController") as
RuntimeAnimatorController;
RuntimeAnimatorController controller = Instantiate(tmpController);
When I do so, I get the following warning when using it as the RuntimeAnimatorController for an Animator component:
The Animator Controller (MyAnimController) you have used is not valid. Animations will not play
The Animator is initialized, valid and I apply the controller like this:
myAnimator.runtimeAnimatorController = controller;
From debugging I can see that the AnimatorController, after loading it from the AssetBundle, has no layers or parameters whatsoever. Which is obviously not the case when viewed from the editor. It has a "Base Layer" and two parameters.
Weird enough it does work when I don't Instantiate the AnimatorController, but use it directly from the AssetBundle:
myAnimator.runtimeAnimatorController = assetBundle.LoadAsset("MyAnimController") as
RuntimeAnimatorController;
That on the other hand leads to a silent crash of Unity when calling the GetBehaviours() method.
This is how I create the AssetBundle:
BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows64);
Answer by rahul-ahuja79 · Sep 12, 2017 at 06:33 AM
RuntimeAnimatorController controller = Instantiate(tmpController); Dont instantoiate it just put directly RuntimeAnimatorController tmpController = assetBundle.LoadAsset("MyAnimController") as RuntimeAnimatorController;
myAnimator.runtimeAnimatorController = tmpController;
Your animation will be played smoothly .
Your answer