Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Passing Texture/Material from Material to Blueprint

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!

Product Version: UE 4.20
more ▼

asked Oct 13 '18 at 09:47 PM in Using UE4

avatar image

125 5 12 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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: Material

  2. 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).

  3. 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: Blueprint 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.

more ▼

answered Oct 14 '18 at 06:18 AM

avatar image

125 5 12 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Oct 13 '18 at 09:53 PM

avatar image

14.7k 76 25 61

avatar image xSheim Oct 13 '18 at 09:56 PM

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

avatar image Everynone Oct 13 '18 at 09:59 PM

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.

avatar image xSheim Oct 13 '18 at 10:07 PM

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).

avatar image Everynone Oct 13 '18 at 10:01 PM

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

alt text

alt text

capture.png (54.7 kB)
cap2.png (49.2 kB)
avatar image xSheim Oct 13 '18 at 10:14 PM

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

avatar image xSheim Oct 13 '18 at 10:32 PM

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? alt text

screenshot-1.png (56.1 kB)
avatar image Everynone Oct 13 '18 at 10:46 PM

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?

avatar image xSheim Oct 13 '18 at 10:58 PM

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: Material Blueprint

1.png (52.5 kB)
2.png (63.1 kB)
avatar image xSheim Oct 14 '18 at 06:21 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question