How do you change the texture on an object with blueprint?

hi all ,

please i would like to know if its possible to make change texture to an object by using a click trigger or something like that ! thks a lot

Yes, via Texture Parameter in material which you can change in blueprint (or you can use different kind of parameter to change look of material, including one that could switch texture) in material or Set Material node (you would need 2 materials in this case)

thanks for your answer, sorry ive just another question, is there is a tutorial for this, cause im realy newish for programming game.thks very much

I also had some trouble trying to figure this out, but I finally made it work. Here is how I did it:

  1. First you need to set up your material with a TextureSampleParameter2D (this will allow you to dynamically edit the materials texture during runtime).

6603-mid_step1.jpg

  1. In your blueprint you have to create a Dynamic Material Instance and set your actor(s) to use this new material (which is based on the material you made in 1). You can do this in the Construction Script (it should be done at the start of your game, or when your actor is spawned). Also, make sure the Element Index of SetMaterial matches the material you want to set on your actor (if you only have one material then just set it to 0).

  1. Now you can use SetTextureParameterValue to change the texture of the Dynamic Material Instance you created in 2.

(It seems I am only allowed to add two images here. The third image can be found in another comment on this page - dig down!)

1 Like

Let me know if this works for you, or if you have any questions.

woah thanks to you SMillard , i’m trying to make it but still complicate for me i don’ understand sens of Actor an Static mesh , does your blueprint setup is trigerable with a button ?

Your Actor is the object that has the material you want to change textures on. You can cast your Actor to a StaticMeshActor as shown in image 2 (this is done to get the StaticMeshComponent, which is the target of SetMaterial). Just use a variable to store your Actor (in image 2 it is called MyActor).

Step 1 and 2 must be done first. During runtime, when you are ready to change the texture on your material, you simply use Step 3 - this could be at the press of a button. I’m sure you can find a guide on how to set up a blueprint button somewhere in the Unreal 4 examples or on the forums. Right now I’m just using the event called when the player presses the fire button (InputFire event).

all you can just use the set material like so…

thks you too M.Wardle. change material is what i was searching for too .

do you think it is possible that if i have an object like a board, can i make an event change material with a library of material completely different .

thannnks

ok finaly i made this ! it s look great and works i can switch material on this static mesh with a loop ,but created in level blue-print ,now i have to make it in an actor blue-print. with trigger

so i tryed to make in a custom blueprint but impossible !!! some help !

This works when I drag in things from the architecture tab but not with things I bring in with Geometry. Any idea why?

Thx so much man!! :smiley:

Unfortunately the 3rd image above is not available so I cannot see how the SetTextureParameterValue is used.

Many people seem to be using Set material, but I assume this is for the WHOLE material and not a texture within the material…is this correct? All I would like to do is set one texture inside a material to other options…mainly for variant cosmetic item options changing a mask for decals (in my example).

Also, If I am using a Dynamic Material Instance Constant…do I still need to create the dynamic texture in the Construction script?

Any help would be greatly appreciated.

Here is my construction and event Blueprint so far trying to emulate what you guys have going… I am trying to get the material instance from this objects blueprint (a cosmetic item) so I can make variants with different masks. The colour variants still work, but the mask doesn’t change. Any thoughts? Thanks in advance.

Hi Discmage,

It’s some time since I worked with this, and I’ve been away from UE4 for some time. Also, I don’t have time to dig into it thoroughly right now, so I’m not sure I can help you 100%. However, I found image 3 for you, and I think what you are missing is the correct parameter name (“Texture_sample_2d”), to match what you set up in image 1. That is, if you did the same as I did in image 1 of course. Let me know if this helps at all.

Also, I am pretty sure you still need to create the material in the constructor; since this is were you actually create the instance of the material. Otherwise I’m guessing it would be null.

39605-mid_step3.jpg

1 Like

Thanks for that third image…I got there in the end! I was doing a few things wrong, some ridiculously simple, others not so much…

The only catch now is to make both the cosmetic colours work AND the decals…as the colours didn’t for some reason. Thanks for all your help! I’ll probably post the results here once I have it all done so others can use the information.

@Andrew Wardle post good and only answer. You can select it as solved.

Please make your own question instead.

IDO ALL STEPS MY STRING TELL ME THAT :SELECT IS DONE BUT IT IS NOT APPER
BUT I FOUND THIS IWILL USED :slight_smile: Runtime Image Loader in Code Plugins - UE Marketplace (unrealengine.com)