Need some help in a script

So I’ve been messing around with object’s meshes and came into trouble when getting Polygon’s material.
The API says:


 getMaterial()[TABLE="class: docutils field-list"]
    [TR="class: field-odd field"]
[TH="class: field-name"]Returns:[/TH]
The polygon material
 [TR="class: field-even field"]
[TH="class: field-name"]Return type:[/TH]
[KX_PolygonMaterial]( or [KX_BlenderMaterial](


As you can see theres 2 return types and the question is: how do I define which return type it should return?
In my case I need KX_PolygonMaterial, but polygon.getMaterial() returns KX_BlenderMaterial

No, it says it returns wether one or the other. What you get depends on the configuration of the mesh. If you do can assume a specific type you better check what you get bye type validation.

if type(polygonMaterial) == bge.types.KX_PolygonMaterial:
elif type(...

In OOP it is usually a better idea to check for instances but in this situation type should be good enough.