Passing Texture/Material from Material to Blueprint

You can get scalars and vectors from dynamic materials easily. Is that enough?

1 Like

One thing I don’t understand:

might be as a texture, but the
material would be what I’m looking for

You have a material already, so… ? You can get material from the mesh directly or from dynamic material’s reference.

Perhaps you could describe example usage.

Are you working with instanced materials? You can get Texture Parameter Value as well. You fetch it by name. here’s what I mean:

256465-capture.png

I’ve been recently trying to pass an information (might be as a texture, but the material would be what I’m looking for) from material to blueprint. It could significantly cut the number of textures/materials I’d need to use, as I need to create a material from a mask and a texture at runtime.
I know that I can work with materials inside blueprints, but this time I’m trying to achieve the opposite - a material sends a piece of information which is being received by a blueprint.
Is this even possible at the current state?
Thanks for any help!

I’ve been thinking about it, but it’s unfortunately not enough. I’d need a texture at least

I’m sorry, I could have been not so clear with that. I want to extract a part of a diffuse texture using masks and send the result to my blueprint. Then a return value could either be a ready-to-use material or just a basic texture.
So let’s say that I have a car and a mask that covers its different parts, i.e. one channel is for wheels. Inside my material I want to get the wheels part from the whole picture (got it). Then I want to send this part of the car’s image to blueprints (as a material or a texture).

Oh, of course I can. I’m sorry, I couldn’t find this function previously. Many thanks

Ah, now as I see there’s another difficulty. For this texture parameter I can’t just select a texture from my content browser. I need to assign a value to it inside my material. So what I have is a output pin of a vector type and a Texture2D Parameter. It means that there’s no way to pin the output value to one of texture param’s inputs which are UV and ViewMipBias. Any ideas?

Not sure what you expect to happen here - v3 is quite different from a 2dTexture.

Let’s say you feed texture a vector value - what would the end result be?

The problem is I need to access the value I’m trying to pin to the Texture2D inside blueprint. I’d need to have a possibility to set this texture parameter inside my material which I don’t. I think the only texture-like parameter I can set inside material is the MaskParam, but… I can’t access the value of this parameter in blueprints. It looks like this:

256486-1.png

256487-2.png

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

Thanks for help @Everynone. I finally got it working and posted the answer

Is it possible to do it with blueprint only?