Blender Materials: getMaterialIndex

getMaterialIndex()
  • Returns the material index.

Return Type:

  • integer
Note:
  • GLSL and Multitexture shading have a material index.
     
  • Singletexture shading doesn't have a material index.
Sample Code

###################### get the material index

# import bge

import bge
 
# get the current scene
scene = bge.logic.getCurrentScene()

# get a list of the objects in the scene
objList = scene.objects

# get object named Cube
objCube = objList["Cube"]

# only one mesh on my cube
mesh = objCube.meshes[0]

# only one material on this mesh
mat = mesh.materials[0]

# get the material index
mat_index = mat.getMaterialIndex()