0

I figured out how to create an asset bundle containing an animation clip, and then loading that animation clip in another project and then overriding existing animation clip with the new one via a script. Basically the goal is to allow users to edit animations.

Everything now thankfully works, but for some reason there is a slowdown. I am not sure what is causing the slowdown when everything is being loaded in start frame:

Here is my code:

protected Animator animator;
protected AnimatorOverrideController animatorOverrideController;
protected AnimationClipOverrides clipOverrides;

void Start()
{
    animator = GetComponent<Animator>();
    animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    animator.runtimeAnimatorController = animatorOverrideController;

    clipOverrides = new AnimationClipOverrides(animatorOverrideController.overridesCount);
    animatorOverrideController.GetOverrides(clipOverrides);
    LoadAnimation();
}

public void LoadAnimation()
{
    StartCoroutine(LoadAnimClip());
}        

IEnumerator LoadAnimClip(string )
{
    var FilePath = Application.streamingAssetsPath + "/Characters/Sonic/Animations/stand";

    var req = AssetBundle.LoadFromFileAsync(FilePath);
    yield return req;
    AssetBundle animationAsset = req.assetBundle;

    AnimationClip animation = animationAsset.LoadAsset<AnimationClip>("Stand") as AnimationClip;

    clipOverrides["Idle"] = animation;
    animatorOverrideController.ApplyOverrides(clipOverrides);

}

If you are wondering what is animationclipoverrides, here is the class:

public class AnimationClipOverrides : List<KeyValuePair<AnimationClip, AnimationClip>
{
    public AnimationClipOverrides(int capacity) : base(capacity) { }

    public AnimationClip this[string name]
    {
        get { return this.Find(x => x.Key.name.Equals(name)).Value; }
        set
        {
            int index = this.FindIndex(x => x.Key.name.Equals(name));
            if (index != -1)
                this[index] = new KeyValuePair<AnimationClip, AnimationClip>(this[index].Key, value);
        }
    }
}
derHugo
  • 83,094
  • 9
  • 75
  • 115
  • 1
    Please use the ***profiler***. The slowdown might be (probably *is*) caused by something else entirely or a difeerence in the *"weight"* (resource-wise) of the projects generating a bottleneck scenario. – CosmicGiant Oct 28 '17 at 20:57
  • 1
    You can also use `Profiler.BeginSample()` and `Profiler.EndSample()` to narrow down the cause. – Draco18s no longer trusts SE Oct 28 '17 at 22:45

0 Answers0