Changing (setting) materials in-game

Greetings Blender Artists.
I am pretty new to blender game engine, so my apologies if this post seems noob-ish :wink:
I have a script that will randomly generate a solar system, and all works well; however, I cannot find a way to create a random material for the planets and such. I have this function for actually making the material:

def makeMaterial(name,diffuse,specular,alpha):
    return mat

and then I go and make my material,


which (i think) makes a good material with random colors and such. Unfortunately, I have no clue as to how to actually assign the material to the object I have. Any help is greatly appreciated, and thanks in advance.


Well, you can’t create materials / geometry in-game if you plan on distributing the game as a standalone executable. What you can do is change the material color using Python (obj.color = [red, green, blue, alpha]).

I see… Thank you Joeman16. Is that it then, just color? I guess I can just look on the api reference for tips on how to add textures and stuff (if you can add textures at all, I don’t know!), so again, thank you for your help.

You can use the videotexture module to dynamically add / replace a specified texture on a material with one from a directory - that’s useful.