UserData (Cocos Creator)

Updated: 03/14/2023

This page is for Cubism version 4.2 or earlier. Click here for the latest version.


UserData is a function that visualizes the user data set in the model’s ArtMesh in Cocos Creator.
User data is a function that allows tags to be assigned as desired to the ArtMesh, which can be used to set the ArtMesh for special processing in the SDK.

Click here for more information on user data.

To use user data in Cocos Creator, follow these steps.

  1. Parse .userdata3.json
  2. Set UserData for the ArtMesh

1. Parse .userdata3.json

Parse .userdata3.json using CubismUserData3Json.
Click here for more information on CubismUserData3Json.

const userData3Json = CubismUserData3Json.loadFrom(jsonString);

The .userdata3.json path can also be obtained from .model3.json using CubismModel3Json.
The obtained path is relative to .model3.json.

const userDataPath = modelJson.fileReferences.userData;

const userData3Json = await this.loadJson(this.fileReferences.userData);

Click here for more information on CubismModel3Json.

Get the ArtMesh data from the parsed .userdata3.json.

const drawableBodies = userData3Json.toBodyArray(CubismUserDataTargetType.ArtMesh);

2. Set UserData for the ArtMesh

Apply the user data obtained from .userdata3.json to the Prefab ArtMesh.

To add user data information to an ArtMesh, use the CubismUserDataTag.

    const drawableBodies = userData3Json.toBodyArray(CubismUserDataTargetType.ArtMesh);
    for (let i = 0; i < drawables.length; i++) {
      const index = model3.getBodyIndexById(drawableBodies, drawables[i].id);
      if (index >= 0) {
        const tag =
          drawables[i].getComponent(CubismUserDataTag) ??
Was this article helpful?
Please let us know what you think about this article.