Passing Texture/Material from Material to Blueprint

I have finally found out how to achieve what I wanted to. It’s a little bit trickier than I thought it was.

  1. Inside my material I created some if statements and scalar values that are used as booleans (only static boolean parameters are available, so 0.f = false, 1.f = true will do the job). It makes my material usable by itself, as a whole, and as a single element. It looks like this:

  1. Then, inside my blueprint I had to create some dynamic materials (one for each part I needed to extract from the main material). Notice that I had to use the function from KismetMaterialLibrary rather than the one from PrimitiveComponent as it allows you to create multiple, independent dynamic material instances (otherwise, when you change a parameter in a single instance, it gets applied to all the instances).
  2. Afterwards I created a function that sets the requied scalar parameters in the dynamic instance I created (it just gets the index and then sets: bUseSingleOutputs=1.0, bOutput_Element_{Index} = 1.0. It looks like this:

The output material is ready to use.

I know that what I showed is not well-optimized as we have to create a big material for the whole object and another one for each part we want to extract, but unless we use it so frequently it won’t hurt that much.

1 Like