I’m trying to blend between two different texture samples within a single material. I’ve got the two texture samples set up with a Lerp but can’t figure out how to gradually animate from one to the other. Any advice would be great.
The key is the alpha input on the lerp node. You’ll need some way to slowly change the value from 0 to 1.
Best way to do this is from a blueprint:
In the material editor:
- Create a scalar parameter (let’s say it’s called “alpha”) and connect it to the alpha input on your lerp node.
In a blueprint:
- Create a dynamic material instance of your material and save it to a variable so you can reference it later
- Assign that DMI to your mesh
- On the DMI, call SetScalarParameter and make sure to use your param name (“alpha”) and set its value.
You’ll need to update that value somehow, so a BP timeline or event loop would do the trick. You could also do it all within the material with a time node but you’d have much less control.
Thanks a lot, that works perfectly! One thing though, doing it this way requires me to assign the newly created DMI to every meshes in blueprints, and I plan on having a lot of different objects in the scene blending at the same time; is there a way to reference an existing DMI in the content browser that I’ve applied to all my assets in the editor rather than creating a new one in blueprints? Thanks again!
DMIs don’t exist in the content browser, unfortunately. I can think of at least two different ways to tackle this:
Create the DMI in a globally-accessible object somewhere. This could be your level blueprint, game instance, some singleton (typically frowned upon), or any other object. When your BP is first created, find and store a reference to that global object (it would basically replace the DMI variable you were already using).
Don’t use a DMI at all and instead rely on a Material Parameter Collection. If you haven’t run into these before they’re really cool. An MPC is basically an object that you create in the content browser that holds any number of vector or scalar variables. Collections are globally accessible from BP and material nodes. So for this to work you’d create an MPC (let’s call it textureVars) and inside that an ‘alpha’ variable. In your material, you’d grab the MPC and plug the alpha var into the alpha node of your lerp. Then, in BP, you access the MPC and update its alpha value. Any mesh with that material will automatically update. No DMIs necessary.
Here are the docs on MPCs. They’re super cool and, although called material parameter collections, can be used for all sorts of other cool things.
Thanks again, I set it up with an MPC as you suggested and it works beautifully! I’ll definitely be using these again in future!
Or much simpler > Time plug into Cos plug into the Alpha of your Lerp