0
0
Unityframework~20 mins

Animation clips in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Animation Clips Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Unity animation clip code?

Consider the following C# code snippet in Unity that plays an animation clip on an Animator component. What will be printed to the console?

Unity
using UnityEngine;

public class PlayAnimation : MonoBehaviour
{
    public Animator animator;

    void Start()
    {
        animator.Play("Jump");
        Debug.Log(animator.GetCurrentAnimatorStateInfo(0).IsName("Jump"));
    }
}
ACompilation error
BTrue
CNullReferenceException
DFalse
Attempts:
2 left
💡 Hint

The animation state may not be updated immediately after calling Play.

🧠 Conceptual
intermediate
1:30remaining
Which property controls the playback speed of an AnimationClip in Unity?

In Unity, you want to make an animation clip play twice as fast. Which property should you modify?

AAnimationClip.length
BAnimator.speed
CAnimationClip.frameRate
DAnimator.SetFloat("Speed")
Attempts:
2 left
💡 Hint

Think about what controls the overall speed of the Animator component.

🔧 Debug
advanced
2:30remaining
Why does this animation clip not play on the GameObject?

Given this code snippet, the animation clip does not play on the GameObject. What is the cause?

Unity
using UnityEngine;

public class AnimateObject : MonoBehaviour
{
    public AnimationClip clip;
    private Animation animationComponent;

    void Start()
    {
        animationComponent = GetComponent<Animation>();
        animationComponent.AddClip(clip, "run");
        animationComponent.Play("run");
    }
}
AThe GameObject does not have an Animation component attached.
BAddClip requires a second parameter to be the clip's length.
CAnimationClip must be assigned in code, not inspector.
DAnimation.Play requires the clip to be named "clip".
Attempts:
2 left
💡 Hint

Check if the required component exists on the GameObject.

📝 Syntax
advanced
2:00remaining
Which option correctly creates and plays an AnimationClip at runtime?

Which code snippet correctly creates a new AnimationClip and plays it on an Animation component at runtime?

A
AnimationClip clip = new AnimationClip();
Animation anim = GetComponent&lt;Animation&gt;();
anim.AddClip(clip, "newClip");
anim.Play("newClip");
B
AnimationClip clip = new AnimationClip();
Animation anim = GetComponent&lt;Animation&gt;();
anim.Play(clip);
C
AnimationClip clip = new AnimationClip();
Animation anim = GetComponent&lt;Animation&gt;();
anim.AddClip(clip);
anim.Play("clip");
D
AnimationClip clip = new AnimationClip();
Animation anim = GetComponent&lt;Animation&gt;();
anim.AddClip(clip, "clip");
anim.Play(clip);
Attempts:
2 left
💡 Hint

Remember the signatures of AddClip and Play methods.

🚀 Application
expert
3:00remaining
How to blend two animation clips smoothly using Animator in Unity?

You want to blend between two animation clips "Walk" and "Run" smoothly based on a speed parameter. Which approach correctly achieves this?

AManually interpolate between the two clips' keyframes in code every frame.
BUse Animation.CrossFade("Run", 0.5f) directly on the Animation component.
CCreate an Animator Controller with a Blend Tree using the speed parameter to blend Walk and Run clips.
DPlay Walk clip, then immediately Play Run clip to switch animations.
Attempts:
2 left
💡 Hint

Think about Unity's recommended way to blend animations based on parameters.