question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Animations don't work at runtime

See original GitHub issue

Hello, I tried to import .glb character with animation, but it doesnt seem to work. It plays fine when I load it at runtime in the editor. But when I build it, the character is not animated. I tried it on Android, iOS and MacOS and neither of these worked. Only in the editor. Do you have a clue, what could I do wrong?

Thanks in advance for your response.

Here’s the code I use:

// Create new mesh.
AnimationClip[] animationClips;
GameObject result = Importer.LoadFromFile(itemFileInfo.FullName, new ImportSettings(), out animationClips);

// Setup animation, if there is any.
if (animationClips.Length > 0)
{
     Animator animatorComponent = result.gameObject.AddComponent<Animator>();
     AnimatorOverrideController gltfAnimatorOverride = new AnimatorOverrideController(gltfAnimator);

     for (int i = 0; i < animationClips.Length; ++i)
     {
          gltfAnimatorOverride["test"] = animationClips[i];
     }
     animatorComponent.runtimeAnimatorController = gltfAnimatorOverride;
}

I’m also attaching the .glb file: mixamo.glb.zip

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

11reactions
hgsujaycommented, Nov 10, 2020

Had the same issue on Android. I was getting error. “can’t use animatioclip set curve at runtime on non legacy animation clips”

Solved it by setting useLegacyClips to true on importSettings.

        AnimationClip[] animClips;
        var i = new ImportSettings();
        i.useLegacyClips = true;
        GameObject result = Importer.LoadFromFile(fileSavePath, i, out animClips);
        GameObject _wrapper = Instantiate(WrapperPrefab, pos, rot);

        if (animClips.Length > 0)
        {
            Animation anim = result.AddComponent<Animation>();
            animClips[0].legacy = true;
            anim.AddClip(animClips[0], animClips[0].name);
            anim.clip = anim.GetClip(animClips[0].name);
            anim.wrapMode = WrapMode.Loop;
            anim.Play();
        }

3reactions
nicholasmaurercommented, Sep 21, 2020

The Playables API doesn’t support legacy animation clips and GLTFUtility was failing to import non legacy clips at runtime, Unity was throwing this error: “Can’t use AnimationClip::SetCurve at Runtime on non Legacy AnimationClips”.

So now I’m using the the legacy Animation system, tested and working on iOS.

private void OnGLTFImportComplete(GameObject result, AnimationClip[] clips) {
        if (clips != null)
        {
            if (clips.Length > 0)
            {
                Animation animation = result.AddComponent<Animation>();
                animation.AddClip(clips[0], clips[0].name);
                animation.clip = animation.GetClip(clips[0].name);
                animation.Play();
                animation.wrapMode = WrapMode.Loop;
            }
        }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Runtime instantiated prefabs not playing animations
Ok, nevermind. Seems to have been due to the default animation culling type, the animations will not play if "Based on Renderers" is...
Read more >
Animator not animating a runtime instantiated child (UNITY)
1 Answer 1 ... With current animator settings, this behavior is normal. You need to change your current animator using Any State section...
Read more >
android - Add animation at run time
I want to animate my AnimatedVectorDrawable at runtime without using .xml files. Actually I'm using .xml files same way as documentation's ...
Read more >
C Runtime animation mix doesn't work
If you have multiple animations, eg A -> B -> C then yes, it will apply A and B and then C and...
Read more >
Animation Engine - Runtime Changes and Fixes
So, I've tried editing the animation track's priority via scripts, and it doesn't work. Editing from the server does nothing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found