Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a question concerning using Python in Blender's Game Engine.

Before I start I want to state that I'm trying to change the color of an object in Blender's game engine. To do this, I'm attempting to find a way to update the texture of the object (I basically want two or three states, red, (yellow), green).

What I'm doing right now is:

scene = GameLogic.getCurrentScene();    
pingMeter = scene.objects['Ping Meter'];
mesh = pingMeter.meshes;
materials = mesh[0].materials;
material = materials[0];

However, when I do print(material.__class__.__name__) it outputs KX_BlenderMaterial. Shouldn't I be getting KX_PolygonMaterial if I'm running the Blender Game Engine? Is there anyway to change color or texture with KX_BlenderMaterial because I can't find anything in the documentation. Can I get an instance of KX_PolygonMaterial out of the code above?

...or should I just take a different approach all together?


EDIT: I'm using Blender 2.65 which uses Python 3 in case anyone is wondering.

share|improve this question
up vote 0 down vote accepted

I determined a way to change the color of an object's material in Python with Blender 2.65. Before my approach above I simply tried something like:

scene = GameLogic.getCurrentScene();
pingMeter = scene.objects['Ping Meter'];
red = mathutils.Vector((1.0, 0.0, 0.0, 1.0));
pingMeter.color = red;

However, this produced no change to the color of the material (should've turned red, and the object was properly lit as well). I found that there has to be an option checked under the materials menu of the object which is Object Color. After checking this box the ping meter successfully change to red in the game.

Additionally, another method I attempted was to get the mesh of the object, get the material of the mesh, and change each vertex color of it. This did not work either, however I speculate that if the Vertex Color Paint option is checked in the materials menu that it would. I have not tested this though.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.