Some doubts about sharedmaterials, materials, material and sharedmaterial

Hello,

did I get it right if I say:

  • renderer.sharedMaterials ALWAYS returns a copy of the array. This means memory allocation!
  • renderer.materials ALWAYS returns a copy of the array. This means memory allocation!

if so, how can I get the number of materials in a renderer without allocating memory?

If you want to get the number of materials in the renderer itself, that’s your only option. If you’re reasonably sure your renderer has the same number of materials in its array as the mesh has material slots you can get the number of sub meshes in the mesh by either looking at the mesh in the mesh filter or skinned mesh renderer.

ok thank you, it’s very weird :confused: