Blender Materials: alpha

alpha
  • get/set the alpha transparency of the material

Type:
  • float number
Range: 
  • 0.0 to 1.0
  • 0.0 = complete alpha transparency
  • 1.0 = no alpha transparency
Note:
  • Transparency must be enabled in the game settings
     
  • Properties menu >> Material >> Transparency checkbox
Sample Code

################## get material alpha transparency

# import bge
import bge

# get the current controller
controller = bge.logic.getCurrentController()

# get object that owns this controller
obj = controller.owner
 
# There's only one mesh on my model
mesh = obj.meshes[0]

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

# get material transparency
mat_trans = mat.alpha

Sample Code

################## set material transparency

# import bge
import bge

# get the current controller
controller = bge.logic.getCurrentController()

# get object that owns this controller
obj = controller.owner
 
# There's only one mesh on my model
mesh = obj.meshes[0]

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

# set alpha transparency
mat.alpha = 0.5