Characters, Animation Controllers and Storyflow

Overview

This article describes how to set up a Character with an Animation Controller and control which animation triggers using Storyflow. This article assumes that you have a character and multiple animations already in Unity.

The steps of this video are described below.

 

Unity - Character & Animation Controller Setup

Character

  1. In the Hierarchy, right click on the character and select Motive > Make Scene Object

  2. In the Inspector, in the Motive Scene Object script find the Name field and give the character a name

This is the name that will be used in Storyflow. In this example, the name is Animated James.

  1. In the Inspector, make sure that your character has an Animator component

  2. If the Controller field is populated, you can remove what is there. We will create a new controller for the character.

  3. Save the project

Animation Controller

  1. In the Project, create a new Animation Controller. This will open the Animator window. (AnimatedJamesController in our example)

  2. Drag in an Animation into the Animator window. This will be the default animation. (The example uses an Idle animation which loops (Stand_Idle_01). )

  3. Add additional animations to the Animator window (In the example, we will use one more animation Stand-Gesture-Up_01)

  4. Right click on the first animation (Idle) and select “Make Transition”

  5. Attach the arrow to one of the other animations

  6. In the Animator window, select Parameters

  7. Create a Trigger (In the example, we will create the IdleToGestureUp trigger.)

  8. Select a Transition

  9. In the Inspector, uncheck “Has Exit Time”

  10. In the Conditions section add the appropriate trigger

    1. In the example, the transition between Stand_Idle_01 state and Stand-Gesture-Up-01 adds the IdleToGestureUp trigger as the condition.

In this case, we want the animation to transition back to the default animation once it has completed.

  1. Create a Transition that starts with Stand-Gesture-Up_01 and goes to Stand_Idle_01

  2. For this transition, “Has Exit Time” should remain checked

  3. Save the project

Character

  1. In the Hierarchy, select the Character

  2. In the Inspector, add an Animator Controller State Listener script

  3. Enter a name into the State field. This name is needed for the Behaviour Model which will be created on Storyflow. (In the example, the state is named JamesAnimationState)

  4. Save the project

  5. In the Inspector, in the Animator component, assign the Animation Controller to the Controller field

  6. In the Animator component, click the “Enable Behaviour Model Usage” button

If you have used this button before, it will be called “Update Behaviour Model File”. It will perform the same function.

  1. Save the project

Animator State Trees

After enabling Behaviour Model Usage, you will see a new file with an “animatorStateTree” extension in the Resources folder. Make sure to add this file to the same Asset Bundle as the Character you are working with. It is not added to the bundle automatically.

If you notice that the animations are working in editor but not on headset it’s likely that the assetStateTree file has not been included in the Asset Bundle.

Storyflow

Catalog Items

Add the Character to a Catalog

  1. If you have not already done so, create a Named Object Catalog for the Character

  2. Add an item to the Catalog

  3. Give it the same name as the name given to your character in the Name field of the Motive Scene Object script

  4. Save the Catalog

Add an Enum

  1. Create an Enum

  2. Enter the name of your animation into the “New Enum Item Name field” and press enter (In this example, it is Stand-Gesture-Up_01)

You can collapse the Enums Definitions section at this point.

Add a Behaviour Model

  1. If you have not already done so, create a Behaviour Model Catalog

  2. Add an item to the Catalog

  3. Give the Catalog item a relevant name (In the example, the name is James Model)

  4. Add a state to the Behaviour Model

The state needs to have the same name that was used in the State field in the Animator Controller State Listener script. In the example, the state is named JamesAnimationState.

  1. Ensure the “Value Definition” is set to Enum and the name of the Enum that was just created. (In this example: JamesAnimationsEnums)

  2. Save the Catalog

Storyflow Script to Test

  1. Create a new Storyflow Script

  2. Name the first child Frame Setup

  3. Add the Character from your Named Object catalog into the Resources section of the Frame. This will appear as a Scene Object Resource in your Script (in the example: James Animated)

  4. Click the + button on Main Frame to create another child Frame

  5. Name the Frame Behaviour Models

  6. Add a Behavior Model Resource to the Frame

  7. Select the Scene Object as the Target (in this example: Animated James)

  8. Add the Behaviour Model that was created in the previous step (in this example: James Model)

  9. A drop down menu will now be visible with the name of the State above it (In this example: JamesAnimationState)

  10. Click the + button next to the drop down field to create a Variable

  11. Give the Variable a name and click the checkmark button

  12. Create a new child Frame

  13. Add a Screen Message Resource (Playable Content type)

  14. Enter Animation Test for the Title and Close this message to Animate for the Message field

  15. Select the Event Link Shortcut (blue button with a white +) at the bottom of the Screen Message Resource and select “Close”

  16. In the new Frame, add the Variable that was created earlier into the Frame

  17. Assign it the name of one of the animations from the drop down menu. This list displays the enum items which we created earlier (In the example = Stand-Gesture-Up_01)

  18. Save the Script

  19. Link the Script to a Scenario

  20. Save the Scenario

Unity or VR Headset - Run the Storyflow Test Script

  1. Run the Scenario linked to the Test Script in Unity or in a VR headset

The character will initially be in the default animation state.

When the Screen Message is closed, the the character will transition into the animation defined the Storyflow script.

Chain Multiple Animations

This describes how to have one animation play directly after another and then transition back to the default animation. In this example, we want to trigger the Stand-Gesture-Up_01 animation, then have the character nod directly after and finally return to the Stand_Idle_01 animation.

Unity

  1. Open the Animation Controller which is assigned to the Character

  2. Delete the transition that goes from Stand-Gesture-Up_01 to Stand_Idle_01

  3. Add an additional Animation. We will use Stand_NodYes_02

  4. Create a transition from Stand-Gesture-Up_01 to Stand_NodYes_02

    1. On this transition, we want “Has Exit Time” to be checked

  5. Create a transition from Stand_NodYes_02 to Stand_Idle_01

    1. On this transition, we want “Has Exit Time” to be checked

  6. Save

  7. In the Hierarchy, select the character

  8. In the Animator component, click the “Update Behaviour Model File” button

  9. Save the project

Unity or VR Headset - Run the Storyflow Test Script

  1. Run the same Scenario as before

This time, when the Stand-Gesture-Up_01 animation is triggered, it will transition to Stand_NodYes_02 when complete. When Stand_NodYes_02 is complete, it will transition to Stand_Idle_01.

Related Articles

Characters and Character Actions

Expression Maps

Lip Syncing

Troubleshooting Lipsync Setup