CubismUpdateController (Cocos Creator)
Updated: 03/14/2023
Summary
By attaching CubismUpdateController to Prefab, you can control the order of execution of each component of the Cubism SDK for Cocos Creator.
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 Cocos Creator.
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.
@ccclass('CubismEyeBlinkController') export default class CubismEyeBlinkController extends Component implements ICubismUpdatable { ... /** Model has update controller component. */ @property({ type: CCFloat, visible: false, serializable: false }) private _hasUpdateController: boolean = false; public get hasUpdateController(): boolean { return this._hasUpdateController; } public set hasUpdateController(value: boolean) { this._hasUpdateController = value; } /** Refreshes controller. Call this method after adding and/or removing <see cref="CubismEyeBlinkParameter"/>s. */ public refresh(): void { ... // Get cubism update controller. this.hasUpdateController = this.getComponent(CubismUpdateController) ! = null; } /** Called by cubism update controller. Order to invoke OnLateUpdate. */ public get executionOrder(): number { return CubismUpdateExecutionOrder.CUBISM_EYE_BLINK_CONTROLLER; } /** Called by cubism update controller. Needs to invoke OnLateUpdate on Editing. */ public get needsUpdateOnEditing(): boolean { return false; } /** Called by cubism update controller. Updates controller. */ public onLateUpdate(): void { // Implement LateUpdate processing } /** Called by Cocos Creator. Makes sure cache is initialized. */ protected start(): void { // Initialize cache. this.refresh(); } /** Called by Cocos Creator. */ protected lateUpdate(): void { if (!this.hasUpdateController) { // If CubismUpdateController is not attached, process from its own LateUpdate. this.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 Cocos Creator.
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.
- Returns whether the scene needs to be updated while it is not running in Cocos Creator.
- 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 Cocos Creator is defined in CubismUpdateExecutionOrder.
- Returns the order of execution of its components.
- 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.
- Example (if you want to call your own component at a time between CubismLookController and CubismPhysicsController):
- onLateUpdate()
- This function is called by CubismUpdateController in a controlled execution order.
Describe the update process to be performed by that component.
- This function is called by CubismUpdateController in a controlled execution order.
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.
this.addComponent(MyComponent1); let component = this.getComponent(MyComponent2); component.destroy(); let updateController = this.getComponent(CubismUpdateController); updateController.refresh();