Is it possible to set a value for nodes with python?

I have a texture that uses nodes for a mask and the transparency is done by a math value there.
I’d like to make a fade in and fade out effect.
But working with transparency and object color doesn’t work anymore.
Can I set it by python or by a property outside of the nodes?

Right click on the value you want to set, choose Copy Full Data Path, and paste that into your script. You can just toss a “= 0” or “=1” or whatever after it to set it

1 Like

Oh, I see. I’ll try that out, thanks

1 Like

Be aware that BPY code only works in the Standalone player in UPBGE 0.3+.
Not in #bge - like this thread is tagged with.

So I guess this wouln’t work in bge, is there any other way?
Can you activate the object color again?

there’s Lamp Color node working in BGE 2.79 . And so, you might want to uncheck the diffuse and specular of it for having the lamp not using CPU (which is not even the case when simply not rendering it - the little camera icon ) and schedule its color and use this 3 channel rgb data as a gate to program your materials nodes. RGB is 3 floats so you can virtually store unlimited values thx to it. Just have to create some math nodes network to “unpack” 3 floats into some discrete values " if R > 0.3 ; True ; False " … you will quickly figure it out … Unless you just gonna use those 3 values directly to schedule some intensity (0-100%) inputs

In UPBGE 0.25 there’s even object Data that is functional (which is not the case for BGE 2.79 if i recall well)

1 Like

You can change the alpha of the material with python.

def main(cont):
    own = cont.owner
    material = own.meshes[0].materials[0] # assuming the mesh has only one material, index 0
    material.alpha = 0.5

When using nodes this will not change the transparency of the material itself, but will change the value for the alpha output socket for the Material or Extended Material nodes, with the main material selected, which you can input to whatever you need.



best to use object color R G or B for this*

Thank you, this seems like a viable option.
But my nodes look like this:

I wanted to make a mask around the image and an effect for distortion.
So this doesn’t work, not even when I’ve tried connecting it to the Alpha socket.

What is the value you want to modify in the node tree?

Even this doesn’t work.
I want to modify the Multiply Value from Alpha in this.

Is there any error in the console?

With a similar setup, it works fine for me.

python-material-alpha.blend (84.7 KB)

There is no error and I can set the value but nothing changes visually
It just reads the alpha as 1.0 the whole time

I must miss something like some sort of settings in materials.
It just doesn’t work even if I’ll make a new material.

I think you don’t have Transparency enabled in the Render Pipeline Options.

Ok it works now.
I had to turn off the Alpha in Texture Influence.