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

**URL:** <https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263>\
**Category:** Asset Creation\
**Tags:** unreal-engine\
**Created:** [April 30, 2021, 3:48pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263 "2021-04-30T15:48:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [April 30, 2021, 3:48pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/1 "2021-04-30T15:48:56Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 1, 2021, 1:16am UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/2 "2021-05-01T01:16:39Z")

</div>

Dynamic material instance and a texture sample parameter.

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 1, 2021, 8:39am UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/3 "2021-05-01T08:39:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 1, 2021, 2:33pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/4 "2021-05-01T14:33:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 1, 2021, 6:53pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/5 "2021-05-01T18:53:35Z")

</div>

Thats going to hurt 🙂 ,

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!  
Wow!

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

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 1, 2021, 8:42pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/6 "2021-05-01T20:42:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 1, 2021, 9:02pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/7 "2021-05-01T21:02:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 1, 2021, 9:56pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/8 "2021-05-01T21:56:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 2, 2021, 10:16am UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/9 "2021-05-02T10:16:08Z")

</div>

@MostHost_LA

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?

 ![rendertarget_](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/d/0d1207ffcbd869c898c6844cc6398f92c801c693.png)

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 2, 2021, 12:09pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/10 "2021-05-02T12:09:04Z")

</div>

@MostHost_LA

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

 ![UE4_BpActor](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/d/dd9d08d5fcb12fc930812d26147f6d9f88dc5eff.jpeg) ![UE4_BpFunctionLibrary](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/f/dff4997f036f1a953d7a9de3d1a2355862005d3b.jpeg)

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 2, 2021, 1:33pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/11 "2021-05-02T13:33:32Z")

</div>

@MostHost_LA

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.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 2, 2021, 5:24pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/12 "2021-05-02T17:24:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KekC\_CSM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KekC\_CSM](https://forums.unrealengine.com/u/KekC_CSM)\
**Post date:** [May 4, 2021, 5:47pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/13 "2021-05-04T17:47:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KekC\_CSM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KekC\_CSM](https://forums.unrealengine.com/u/KekC_CSM)\
**Post date:** [May 9, 2021, 11:06am UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/14 "2021-05-09T11:06:46Z")

</div>

![ue4_bp_forums_03](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/2/b285da7740901a5d6ef3f43e8cb8ecf34d4b0b25.jpeg)

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 9, 2021, 7:40pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/15 "2021-05-09T19:40:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![midgunner66](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/midgunner66/32/466711_2.png) [@midgunner66](https://forums.unrealengine.com/u/midgunner66)\
**Post date:** [May 9, 2021, 8:47pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/16 "2021-05-09T20:47:40Z")

</div>

> [@anonymous\_user\_232197e21](#):
>
> Still a strange way I say of doing it, we should have an option to simply replace textures globally without thisn work around.

There is: it’s called [Material Parameter Collections](https://docs.unrealengine.com/en-US/RenderingAndGraphics/Materials/ParameterCollections/index.html). They can be changed both in the editor and through blueprints.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 9, 2021, 8:50pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/17 "2021-05-09T20:50:11Z")

</div>

> [@anonymous\_user\_232197e21](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 9, 2021, 11:26pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/18 "2021-05-09T23:26:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Poet\_11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Poet\_11](https://forums.unrealengine.com/u/Poet_11)\
**Post date:** [May 9, 2021, 11:27pm UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/19 "2021-05-09T23:27:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 10, 2021, 12:10am UTC](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263/20 "2021-05-10T00:10:43Z")

</div>

> [@anonymous\_user\_232197e21](#):
>
> Wouldn’t this still be occupying texture samples and take up two places making the material more “heavy” with yet another texture node?

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

> **[Material Parameter Expressions](https://docs.unrealengine.com/5.3/en-US/material-parameter-expressions-in-unreal-engine/)**
>
> Expressions that expose properties to Material Instances to be overridden in child instances or modified at runtime.

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.

[Next page](https://forums.unrealengine.com/t/how-can-i-change-a-texture-globally-in-a-material-function/227263.md?page=2)
