Realtime Material Issue

Hey all. Yep, it’s me, that guy who drops in once in a blue moon when he’s having problems with the game engine and can’t seem to figure them out.

So here’s the deal: I’m trying to control the diffuse color of a material in realtime via a Python script and a couple of game properties. According to the console output, everything is working fine; there are no errors or warnings relating to what I’m trying to do raised. But in the Game Engine, it isn’t working at all. The diffuse color stays statically what it was before starting.

I’ve tried several things, such as disabling Material Caching and using GLSL mode instead of Multitexture, to no avail.

Here’s my script:

CloudColControl.py

from Util import *

cont = bge.logic.getCurrentController()
own = cont.owner

mat = own.meshes[0].materials[0]

print(mat.diffuseColor)

if own['intensity'] < 0.001: #No specific intensity set; set according to Type
   if own['type'] == 0: #Normal, white clouds
       mat.diffuseColor = (1,1,1)
   elif own['type'] == 1: #Overcast, gray clouds
       mat.diffuseColor = (.375,.375,.375)
   elif own['type'] == 2: #Storm, very dark clouds
       mat.diffuseColor = (.05,.05,.05)
   #May add more later
else: #Use the specified intensity, for fine control
   mat.diffuseColor.r = own['intensity']
   mat.diffuseColor.g = own['intensity']
   mat.diffuseColor.b = own['intensity']

The reason I’m trying to control diffuse color instead of intensity is that it’s a shadeless material, so diffuse intensity has no effect.

Here’s a video; you can see for yourself how it’s not working. https://youtu.be/rzrUQsdVF4k
I don’t know, am I just missing something really obvious here?

Edit: Oh, yeah, maybe I should add that I’m using Blender 2.79, not UPBGE.

If i am right you can’t change the diffuse color of a texture.

But you can change the object color

obj = an object
obj.color = [1,0,0,1] #edit: forgot to put in the alpha channel(0 == full alpha, 1 == no alpha)

don’t forget to check the use object color checkbox in it’s material setting

if you need to mess with the texture then i got a resource here to swap textures during runtime

1 Like

Oh? Well, that would certainly explain why it isn’t working. :stuck_out_tongue_closed_eyes: Although if that is the case, I do wonder why diffuseColor is even writable. Thanks for the info! I think I’ll wait and see if anyone else has any input, and if not, mark your post as the solution (provided it works :wink: [which it does]).

Well your not saying what you want to achieve.

  • obj.color + object color checkbox checked in the materials tab, works.
  • texture swapping, works.

if you want to color the diffuse color of a texture, then make the texture white (the parts that needs color adjustments in game) then simply use obj.color and see the texture change in color, works.