Creating Materials

There are generally three ways to create materials:

1. Manual Creation

2. Materials from Models

Refer to the Model Import and Usage tutorial. First, import the model into the editor. In most cases, the model will automatically bind its material, requiring no user action.

2.1. Remap Material

To modify the model's material, click the duplicate and remap button to generate a copy of the material. Note that Remap will modify the model's preset, affecting all model instances (as shown below):

2.2. Incremental Modification

To modify only a specific model's material, use the incremental modification feature:

3. Bind Material

Directly drag the material into the scene to bind it.

4. Script-Based Method

You can also create or modify materials via scripts. Below is a demo that replaces a material by attaching a script to a cube entity:

export default class extends Script {
  onStart() {
    // Get all renderers
    const renderers = [];
    this.entity.getComponentsIncludeChildren(MeshRenderer, renderers);
    const renderer = renderers[0];
 
    // Modify material directly
    const material = renderer.getMaterial();
    material.baseColor.set(1, 0, 0, 1);
 
    // Or replace the material
    const pbrMaterial = new PBRMaterial(engine);
    const material = renderer.setMaterial(material);
  }
}

Was this page helpful?