- Home /
Loading Animations from Asset Bundle
I have a bunch of mobs for my game saved in an asset bundle. Some have legacy animations and others use mechanim. My problem is that some of my mechanim assets have separate FBX's containing the animations for the prefab that I instantiate. If I look through the object[] array of my asset bundle I do see those animator FBXs, but the controller in the being's FBX refers to animations in those other FBXs. I don't know how to re-associate them at runtime so the animations will play. The monster loads and enters its idle animation somehow but then I get a bunch of red errors whenever my game tries to change the animation.
The only thing I could find out there was help on loading legacy Animations from asset bundles.
Thanks in advance!
I'm also trying something similar, Prefab in one asset bundle and legacy animations in another. But the animation is not playing. I'm loading the prefab and playing animation as,
AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
if (assetBundle == null) {
return null;
}
GameObject prefab = assetBundle.LoadAsset(name);
Instantiate(prefab, targetTransform.position, targetTransform.rotation);
assetBundle.Unload(false);
foreach (AnimationClip animationClip in animationClips) {
string clipName = animationClip.name;
animation.AddClip(animationClip, clipName);
}
foreach (AnimationClip animationClip in animationClips) {
string clipName = animationClip.name;
animation.PlayQueued(clipName, Queue$$anonymous$$ode.CompleteOthers);
}
Any idea how to do that?
Answer by Baalhug · Sep 26, 2018 at 02:02 PM
what you need is an animator controller: https://docs.unity3d.com/Manual/class-AnimatorController.html
Just add the animations to the controller before starting
Answer by MaryamKamel · Jul 28, 2020 at 04:33 PM
if your enemies are prefabs that has animator controller then probably unity could not generate the animator class in runtime because of the stripping engine code Checkbox you can find it in player settings> other setting , uncheck that box and all your animations will work fine