How to hook up alpha channel of a texture in C++?


i try to generate a bunch of materials with a plugin function in C++. Basically for each materail i have one texture an wanna hook it up to the material blueprint node in a way shown i this picture:


the upper connection (RGB to Base Color) is no problem i do this with the following line of code:

UMaterial* material = ... ;
UMaterialExpressionTextureSample* TextureExpression = ... ;

material->BaseColor.Expression = TextureExpression;

I just cant figure out, how to connect the A with the Opacity Mask. Any suggestions are very welcome.

1 Like

Finally i got it!

First you need to tell it, to use the texture expression for the opacity mask:

material->OpacityMask.Expression = TextureExpression;

After that you need to activate a mask for the opacity mask input:

material->OpacityMask.Mask = 1;

And then you can switch on/ off which of the channels you are going to need:

material->OpacityMask.MaskR = 0;
material->OpacityMask.MaskG = 0;
material->OpacityMask.MaskB = 0;
material->OpacityMask.MaskA = 1;
1 Like

That was a tough one - I’m going to keep this one around because I’m sure I will forget.

1 Like

Thank you so much for sharing, I’ve wasted so much time trying to find this!