BGE Changing material of Objects

Hey guys, new to BGE and I’m a little curious as to how clicking objects work.

The scene is as follows; I have a cube, when I left click it turns red, when I left click again, it turns back to the original colour (grey). But I have two separate meshes, a grey cube and a red cube. I only want to change to the material, but I have no idea how. Any ideas?

Thanks, Zero.

You could use an action to animate the material’s color, or you could check the Object Color box in the materials tab and then just just set the color using the KX_GameObject.color property.

Sorry man, I wish I knew what to do with the help you’ve given me. I’m a newby to BGE and understand very little.

Actually I just made a test blend, and it seems like you only need to have object color checked if you’re using GLSL. Here’s the file. Just hit space to turn the Cube red. The code is literally 4 lines.

change_color.blend (475 KB)

Ah it seems simple enough. Though I’m unsure how to get it working. Is there a way to set it to a specific material?

Here’s my .blend;

The object has two materials, I just wanna switch that.

I assume that ‘own.color = [255,0,0, 1]’ Is the colour red, right?

Edit: It’s the very left cube that I’m editing. Cube1. Just to clarify…

As far as I know, it’s not possible to change objects’ materials in the game engine. You’ll have to use one of the two methods I suggested or just replace the mesh like you’re already doing.

Alright, thanks Mobious, you’ve helped a lot. =]