How can I change a texture globally in a material function?

Hi, I have a material function I would like to change its 2d texture paramater globally in a BP on a per level basis, basically to change or replace textures. Is there a way I can communicate with it from BP directly?

I was hoping Material paramater collection would have the texture option to help with this but we don’t have that so far. Any other way of doing this?

Thank you,

Dynamic material instance and a texture sample parameter.

Thanks MostHost for your reply, however and correct me if i’m wrong, the material function that I have is being used on many various assets in the scene, I can’t get each one of them and create a material instance for each, that would be like doing it for 50 different objects or so, I would like the base material function to change its texture so that all the scene objects using this material function take effect automatically.

How can I get that base material function into a custom BP or a level BP to do this? Unless my approach is wrong on this and there is a step I am missing.

Edit: I also have scalar values on this material function which I am able to tweak globally with a material paramter collection, but sadly this feature doesn’t allow me to change any textures in a similar manner, which is why I’m hoping there is some other way.

Thanks again.

You can have the texture sample within the function. Then add the function to all materials and affect the change from it.
But yes you’d only be able to swap that texture if you used instances…

Still, it would override the other texture

Thats going to hurt :slight_smile: ,

this means if I have 50 characters that need their textures changed via that one material function present in all of their materials, and if each of the 50 unique characters has 3 or 4 material elements all sharing this one function, I have to make material instance for every single one of them and their elements and then dig to the material function in every single one of them and assign a a bp that would enable me to change that one texture!

This means I have to create material instance over 200 hundred times just to change one texture in one material function!

Is there really no other more elegant way of doing this? Something similar to how material parameter collection does it but for textures instead?

Not really.
You could use a render target and then write the texture to the render target.

You still need to apply the MF to every material, but once that’s done you can use BP to just write to the texture that’s used in the MF and you are done without having to create instances or any other stuff

(btw there’s no need to create instances anyway unless you need to override the texture you place in the MF).

hmmm, I’ve never used render targets that way before, always used them in the scene directly but never tried writing a texture to it via BPs. I always thought they would be expensive to use in general so I avoid them when possible and for something as trivial as changing a global texture like this it never occured to me that I might need it.

Maybe it doesn’t occupy performance given its a one time task stored offline? I will investigate further thank you for your input it really helped. If you have anything further to share please do so.

The cost is the same as another texture sample.
You aren’t writing a rendered image to it continously. You are just copying a texture into it once - or even multiple times, but its not continuous so the performance hit is nonexistent.

This is commonly used for things like mud on clothing.

You capture a shot of the target when he fell flat on his face, determine the areas of the UV that need to grime up, and produce the grime texture to pass onto the cloth.
(Easier said than done when all your UVs are different, but anyway)…


Thanks for all the help I really appreciate it. I’m really trying to wrap my head around accesing the material function in BP.

Doing all this on a specific material or actor is straight forward, but I can’t seem to access a material function Material from my asset list to change its parameters in order to assign a render to target texture on it.

I mean how do you go about grabbing it, I even tried casting it with no success so far.

For a quick test I thought of placing this whole thing in a level BP and assign a button to change textures during runtime (even though in practice I will be pre-loading these textures and not changing them during runtime).

Here’s what I have so far… whats next?


I did this for a quick test but this is what I DONT want to be doing.

Here I have created a BP function library with the following inputs, which basically creates a material instance in an actor and based upon the level of the game it switches to a new texture:
It digs through the material of said actor - finds the Material function instance in this material - changes the texture of that material function based on the switch.

imagine applying this on every single actor I need :slight_smile: and tweaking it this way, its just a redundant aspect if I can simply have a way to access the master material function like we were talking about.


Ok got it I think,

I just went to level Bb/game mode dragged it from event begin play - Draw material to render target and picked my canvas.

I had created an unlit material with the texture i want to replace. and thats it.

It seems this fires once and not continioulsy. I assume this is the correct approach for this?

thanks for all the help. Seemed simple after all. Still a strange way I say of doing it, we should have an option to simply replace textures globally without thisn work around.

1 Like

Make an actor to manage it rather than use level bp.
But that is the approach

Need make one Material who used two switchable textures (low res and highres) and texture highres place in world in place texture of lowres with same scale and coordinates. Switch enable/disable in setting options in menu this function.

Also need in settings options enable/disable external PAK-file with this highres textures and Material function read textures from this PAK-file.

Anyone have idea.

Thanks for trying to help but I don’t want to have switches in my material editor, furthermore would’nt this cause two texture samples to always be present in the material instead of one which is directed by render to texture.

There is: it’s called Material Parameter Collections. They can be changed both in the editor and through blueprints.

No, not necessarily.
The switch can be smart when the material is compiled. It depends on which kind of switch you use.

A normal If statement compiles all branches.
A Static Parameter Switch does not. You can see this by the fact the instance gets recompiled every time you flip the switch (at least initially, then the shader is store and its harder to notice).
Oh and well… parameters linked to the switch also disappear from the instance.

It’s a very good way to make a material for the marketplace, where users can disable whatever they don’t need without having to actually open up and edit the material.

Either way, I think Kek was trying to get help, not provide help. It’s just not a very good place for it since the issue isn’t all that related as far as I understand his question.

Thanks again, so just to understand this correctly, in some other case, should I have switch in my materials and two textures to change from, wouldn’t this still be occupying texture samples and take up two places making the material more “heavy” with yet another texture node?

Sadly Material Parameter collection does not allow textures to be changed, only values and vectors.

Obviously this depends on what you plug into what.

A boolean can only ever be either true or false.
By nature, you can’t change the value of a “static” parameter switch at runtime.

As such, only 1 branch of the expression will be actually evaluated using the switch

Now, if you plug the same texture output into both true and false - obviously, the texture is used in both pathways taking up a texture sample.

On the other hand,
if one of the pathways just updates an existing texture (maybe add a multiply by .5 or a contrast node or something).
While the other pathway multiplies times a new texture sample…

switching the parameter on and off within the instance will cause the material to either Use or Not use an extra texture sample.