Changing texture in real time

Hi!,
I’m new to UE. I’m working on architectural VR and I have a question on how to change texture in real time?
I have a room floor and wanted to change a texture in real time as I can have a button kind of something to change it.
I tried solving my self and watching tuts on YouTube but failed.
Any suggestions would be greatly appreciated.
Thank in advance.

Hello friend, did you manage to solve the problem? I have the same problem on my project. The craziest thing is that it worked correctly in ue 4.24, after I upgraded to 4.26 it just doesn’t work…

It’s quite easy once you know how it works. In a nutshell: you need a widget with a button and a reference to the mesh in the scene. When you press the button you can make it (on button pressed) change the material for that mesh.

Check your blueprint for compile errors if it stops working in a new engine version. You can click on the message and it will send you to the broken node.

I’m selling a fairly modular UI on the marketplace. It’s $ 50 US and does that and more for you if you need an example to look at or you can just use it as is for most projects.

Your material needs a texture parameter of the texture you want to swap.

In your objects blueprint you give your object a dynamic material instance of your material, probably in the construction script.

In the blueprints event graph add a custom event and use the “set texture parameter value” node to change the texture.

Trigger the custom event with your button press.

2 Likes

Well, technically he asked for replacing the texture. But in reality you can’t apply just a texture to a mesh. It would be a material, probably with normals and roughness settings and so on. That means to replace the ‘texture’ on the floor it would be a lot easier to make a different material and replace that material. Let’s say you wanted to change from tiles to a carpet it would definitely require different materials.

Having said that, it is possible to just replace the texture if everything else stays the same within the material. Otherwise you have to change those other material parameters as well.

1 Like

If the whole material needs to be swapped you would also create a dynamic material instance.

Then create a custom event which exchanges this material.

I’ll post an example when back at my computer.

If you don’t wand any effects like fading you don’t even need a dynamic material. You can just use the “Set Material” node in your blueprints event graph:

nope :slight_smile: you don’t need a dynamic material. You can use the Set Material node with any material:

1 Like