Playback motion from a script.

[Last updated: 01/30/2020]

This page describes the procedure for setting up MotionController for Cubism models.
The following assumes that the SDK will be added to a project that has “Import SDK”.

 

Summary

If you want to play animations from scripts without using Unity's Mecanim, Cubism SDK for Unity allows you to set it up by using a component called “CubismMotionController”.

For more information on CubismMotionContoller, please click here.

CubismMotionController requires the Animator component to operate.
However, CubismMotionController cannot coexist with motion playback using Animator's AnimatorController.
Therefore, when using CubismMotionController to play motion, do not set AnimatorController to Animator.

To make the above settings for a Cubism model, follow the steps below.

  1. Attach CubismMotionController
  2. Prepare a component that calls the instruction to play the AnimationClip
  3. Create a button to play the motion

 

1. Attach CubismMotionController

Attach a “CubismMotionController” to the GameObject that will be the root of the model to play the animation.

CubismMotionController has one setting item.

- Layer Count: Total number of animation layers managed by CubismMotionController. The range of values to be set is 1 or more.

 

When a CubismMotionController is attached to a GameObject, if neither Animator nor CubismFadeController is attached to that GameObject, they will be attached at the same time.

CubismMotionController requires Animator because it uses Playable for motion playback.
If the AnimatorController is set as the Controller of the Animator component, it will take precedence.
If you are using CubismMotionController, do not set anything here.

CubismFadeController is also required because CubismMotionController uses MotionFade to blend motion and motion.
If CubismFadeController.CubismFadeMotionList is not set, set the generated .cadeMotionList.
For details on .fadeMotionList settings, please click here.

 

2. Prepare a component that calls the instruction to play the AnimationClip

Create a C# script called “MotionPlayer” and rewrite the code as follows.
Here, we are trying to play the argument AnimationClip.

 

Attach the MotionPlayer you created to the GameObject to which you attached the CubismMotionController in step 1.

 

This completes the setup for playing back motion from a script.
You can play the motion by calling MotionPlayer.PlayMotion() from an external script etc. and passing the AnimationClip you want to play as an argument.

 

 

Here we call this function from a button.

 

3. Create a button to play the motion

Create a Button in the Scene by clicking on the Create button at the top of the Hierarchy window or by right-clicking on the Hierarchy window and clicking on UI > Button.
The created Button can be placed anywhere.

 

Make the Button you created selected and click the “+” at the bottom of the Button's “On Click()” from the Inspector window.
Drag and drop the GameObject of the model in Hirarchy onto the added list and select MotionPlayer / PlayMotion() from the drop-down menu on the right.

 

Finally, set the AnimationClip to be played as the argument.

 

This completes the setup. When executed in this state, the motion will play when the button in the Game view is clicked.

© 2010 - 2022 Live2D Inc.