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.