How do I access multiple materials of a meshInstance?

For example: meshInstance.material will access the first material, but what if the meshinstance (render component) has many materials? How can I access them?

I tried the folowing but it doesnt seem to work:

Check out the documentation please: RenderComponent | PlayCanvas API Reference

Thanks, but I cant find anything there that hints at how to access multiple materials.

The only thing I found there that seemed relevant is materialAssets but there is no explanation so I tried to use it in different ways but none of them worked. :frowning:

You need to iterate through the render component mesh instances to access each material:

this.entity.render.meshInstances.forEach(meshInstance => {
   const material = meshInstance.material;

Okay Thanks. So actually ‘MeshInstance’ really means ‘Material Instance’?

It’s something more, a mesh instance is the combination of three things:

  1. Mesh (a model, polygons)
  2. Material (shader plus params/textures)
  3. Node (entity, the position/rotation/scale, where to render the model)

These get submitted on each frame on each layer that’s to be rendered, as draw calls.

1 Like

Good to know. Thanks!!

1 Like