CubismUpdateController

Updated: 10/21/2020

Summary

By attaching CubismUpdateController to Prefab, you can control the order of execution of each component of the Cubism SDK for Unity.

Since the order of execution of each component is important in the OW method, it is essential to use CubismUpdateController to follow the specification.
If you do not use CubismUpdateController, for example, because you do not need to control the order of execution, functions such as Expression may not be processed correctly depending on the order of execution because the order in which components are executed is determined by Unity.

To control the order of execution of user-created components, implement ICubismUpdateable in the components.

Implement ICubismUpdateable

The ICubismUpdateable interface is inherited by the component that controls the execution order.

If CubismUpdateController is not attached, the OnLateUpdate process will not be executed, so the following snippet allows that component to work by itself.

public sealed class CubismRenderController : MonoBehaviour, ICubismUpdatable
{
    public bool HasUpdateController { get; set; }
  
    public bool NeedsUpdateOnEditing
    {
        get { return true; }
    }
  
    public int ExecutionOrder
    {
        // Execution order for this component
        get { return CubismUpdateExecutionOrder.CubismRenderController; }
    }
  
    public void OnLateUpdate()
    {
        if(HasUpdateController)
        {
            // Implement LateUpdate processing
        }
    }
  
  
    private void OnEnable()
    {
        // Whether CubismUpdateController is attached or not
        HasUpdateController = (GetComponent<CubismUpdateController>() ! = null);
    }
  
    private void LateUpdate()
    {
        if(!HasUpdateController)
        {
            // If CubismUpdateController is not attached, process from its own LateUpdate.
            OnLateUpdate();
        }
    }
}
public sealed class CubismEyeBlinkController : MonoBehaviour, ICubismUpdatable
{
    public bool HasUpdateController { get; set; }
  
    public bool NeedsUpdateOnEditing
    {
        get { return false; }
    }
  
    public int ExecutionOrder
    {
        // Return the order of execution of this component.
        get { return CubismUpdateExecutionOrder.CubismEyeBlinkController; }
    }
  
    public void OnLateUpdate()
    {
        // Implement LateUpdate processing
    }
  
  
    private void OnEnable()
    {
        // Whether CubismUpdateController is attached or not
        HasUpdateController = (GetComponent<CubismUpdateController>() ! = null);
    }
  
    private void LateUpdate()
    {
        if(!HasUpdateController)
        {
            // If CubismUpdateController is not attached, process from its own LateUpdate.
            OnLateUpdate();
        }
    }
}
  • HasUpdateController
    • Sets whether CubismUpdateController is attached to the Prefab.
  • NeedsUpdateOnEditing
    • Returns whether the scene needs to be updated while it is not running in Unity.
      Since CubismUpdateController also runs in Editor Mode, it returns false if the component does not need to be updated even when it is not running.
  • ExecutionOrder
    • Returns the order of execution of its components.
      The component with the smaller value is called first.
      The execution order of each component in the Cubism SDK for Unity is defined in CubismUpdateExecutionOrder.
    •  If the user has added a component that controls the order of execution, refer to the definition of CubismUpdateExecutionOrder and note when it is called by the value returned here.
      • Example (if you want to call your own component at a time between CubismLookController and CubismPhysicsController):
        • CubismLookController is set to 700 and CubismPhysicsController is set to 800, so set your own component to return 750.
  • OnLateUpdate()
    • This function is called by CubismUpdateController in a controlled execution order.
      Describe the update process to be performed by that component.

Caution When Adding or Removing Components during Execution

The component that controls the order of execution by CubismUpdateController does so at the timing of OnEnable().
If all components are pre-attached to the Prefab, there is no problem, but if you dynamically add or remove components during scene execution, you must explicitly call CubismUpdateController.Refresh() to reload them.

gameObject.AddComponent<MyComponent1>();

var component = gameObject.GetComponent<MyComponent2>();
DestroyImmediate(component);

// Have CubismUpdateController reload the components it controls
var updateController = gameObject.GetComponent<CubismUpdateController>();
updateController.Refresh();
Was this article helpful?
YesNo
Please let us know what you think about this article.