Hi BA community! I’m very new to python scripting and BGE, so I apologize in advance if I’ve made some very basic errors.
Here’s what I’m trying to do: tell an empty (“empty”) to add a rigged character (“figure”) into the scene, and generate a random color for the character’s mesh (“mesh”). This works fine when I try to add a basic cube mesh, but when I try to add the character, the color stays white and doesn’t get randomly chosen. I figure it’s likely because “mesh” is a child of “figure” so its color attribute isn’t getting called, but I’m not certain how to do that.
I’ve also ensured that the Object Color option is checked for “mesh”, and tried calling on “diffuse_color” instead of “color” attribute, but that doesn’t seem to work either. I’ve attached the relevant script below. Any help would be appreciated!
import bge
import random
sce = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
r = random.random()
g = random.random()
b = random.random()
for y in range(1):
#obj = sce.addObject("Cube","empty")
#obj.color = [r,g,b,1]
obj = sce.addObject("figure","empty")
for child in obj.children:
if "mesh" in child:
bpy.data.objects["mesh"].active_material.color = [r,g,b,1]