Documentation

Support

Unity Studio

Open Unity Studio

Unity Studio

Play animations in your scene

Play animations in your scene either automatically or in response to buttons or Logic scripts.
Read time 2 minutesLast updated 4 hours ago

You can start the animations you create with the Animation Director and Animation component in several ways:

Play an animation automatically

Autoplay starts an animation automatically when the Animation component or Animation Director becomes active. By default, this happens when the scene starts, unless you disable the object or component. If the object is inactive when the scene loads, the animation doesn’t start until you enable the object later. To play an animation when the scene starts:
  1. Select the Animation Director or the object that contains the Animation component in the Hierarchy panel. The Inspector panel displays.
  2. In the Inspector panel, enable Active (the checkbox next to the object's name) to ensure the object is active on start.
  3. If your animations aren't already set up on the object:
  4. Set Autoplay to the animation or timeline you want to play automatically.
  5. Press Play.
The chosen animation plays when the scene starts.

Use a button to play the animation

Buttons provide an alternative way to trigger an animation in your scene without the need to set up separate Logic scripts. The animation starts when the user interacts with the button. To set up a button to play an animation:
  1. Select a Button object in the Hierarchy panel. If there are no buttons, select Add (+) > UI > Button to add one.
  2. In the Inspector panel, enable Interactable.
  3. Navigate to the When button is clicked section of the button's properties.
  4. Select Add (+) to add an animation section to your button.
  5. Expand the dropdown and select either the Animation Director or an object that contains an Animation component.
  6. Choose an action (Play, Pause, Stop).
  7. If shown, set Name to the animation clip you want to trigger.
  8. Optionally, set Speed to change the playback speed of the animation.
Your button is ready to use in the scene. In Play mode, select the button to start your animation.

Set up a Logic script to play the animation

A Logic script lets you control exactly when an animation starts, stops, and pauses. For example, you can trigger an animation after an event such as a collision or a key press. You can use the following nodes in your Logic scripts to control your animations: For an example of how to create a script that activates an animation when the user presses a key, refer to Trigger an animation with a key press.

Additional resources