0
0
Unityframework~20 mins

Animation events in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Animation Event Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output when an animation event triggers this method?
Consider the following Unity C# script attached to a GameObject with an animation that has an event calling PlaySound. What will be printed in the console when the animation event fires?
Unity
using UnityEngine;

public class AnimationEventTest : MonoBehaviour
{
    public void PlaySound()
    {
        Debug.Log("Sound played at frame " + Time.frameCount);
    }
}
ASound played at frame [current frame count when event fires]
BSound played at frame 0
CSound played at frame 1
DNo output, method not called
Attempts:
2 left
💡 Hint
Animation events call the method at the exact frame they are set in the animation timeline.
🧠 Conceptual
intermediate
1:30remaining
Which statement about Unity animation events is true?
Select the correct statement about animation events in Unity.
AAnimation events require the method to be static.
BAnimation events can call methods with one parameter of type string, float, int, or object.
CAnimation events can call any method regardless of parameters.
DAnimation events can only call methods with no parameters.
Attempts:
2 left
💡 Hint
Check Unity documentation on animation event method signatures.
🔧 Debug
advanced
2:30remaining
Why does this animation event method cause a runtime error?
Given the method below, an animation event calls TriggerEffect but the game crashes with a NullReferenceException. What is the cause?
Unity
using UnityEngine;

public class EffectTrigger : MonoBehaviour
{
    private ParticleSystem effect;

    public void TriggerEffect()
    {
        effect.Play();
    }
}
AParticleSystem.Play() cannot be called from animation events.
BThe method signature is invalid for animation events.
CThe ParticleSystem variable 'effect' is never assigned, so it is null when Play() is called.
DThe method must be static to be called by animation events.
Attempts:
2 left
💡 Hint
Check if all variables used in the method are properly initialized.
📝 Syntax
advanced
1:30remaining
Which method signature is valid for an animation event with a float parameter?
Choose the correct method signature that can be called by an animation event passing a float value.
Apublic void SetSpeed(float speed, int multiplier)
Bprivate void SetSpeed(float speed)
Cpublic float SetSpeed(float speed)
Dpublic void SetSpeed(float speed)
Attempts:
2 left
💡 Hint
Animation event methods must be public and have zero or one parameter.
🚀 Application
expert
3:00remaining
How to pass a string parameter via animation event and use it in the method?
You want to trigger a method via animation event that receives a string parameter to display a message. Which code snippet correctly implements this?
Unity
using UnityEngine;

public class MessageDisplay : MonoBehaviour
{
    public void ShowMessage(string message)
    {
        Debug.Log("Message: " + message);
    }
}
AAdd an animation event calling ShowMessage with the string parameter set in the animation timeline.
BAdd an animation event calling ShowMessage with no parameters and set the message inside the method.
CAdd an animation event calling ShowMessage but pass an int parameter instead of string.
DAdd an animation event calling ShowMessage with multiple parameters separated by commas.
Attempts:
2 left
💡 Hint
Animation events allow passing one parameter of type string, float, int, or object.