Scripting the PlayCanvas Editor

And another one, I found a missing action in editor: I am unable to assign a material on a Mesh Instance of multiple model assets at the same time. I would have to assign them one after the other.

  1. Select a number of Model assets.
  2. Open the browser console.
  3. Set your Material asset id and Mesh Instance slot, paste the code and execute.

assetModelSetMaterial(15325478, 0);

function assetModelSetMaterial(assetId, slot) {
  const type = editor.call("selector:type");

  if (type !== "asset") {
    return false;
  }

  const items = editor.call("selector:items");

  if (!items || items.length === 0) {
    return false;
  }

  items.forEach((item, index) => {
    item.set("data.mapping." + slot + ".material", assetId);
  });

  console.log("--- Finished execution ---");
}
3 Likes