A blog about VFX, scripting, van renovation, and some other gubbins.

@henloco

Animating materials from blueprints without using timelines

Timelines are expensive, so in this guide I will demonstrate how to trigger a simple animation on a material using blueprint events.

Published 8th October 2020 by Henry

The problem

It’s simple enough to animate a material, and also to change material parameters through blueprints. However, I found that it wasn’t straightforward to trigger a material animation from a blueprint event without having to resort to Timelines, which are expensive because they add a tick.

The solution

The key part to my solution is to use the Game Time to set the start time in the material. The animation then runs from that start time.

How

For this demo I’ll create a material function which will take the start time in seconds as a scalar parameter, and output an alpha to control a linear interpolation within the material I want to animate.

Then, I will create a blueprint which will fire events when keys are pressed, which will set the start time in the material.

I have provided .txt files for the material and blueprint node graphs which you can copy and paste.

MF_TimeLerp


Download MF_TimeLerp material function node graph

The important inputs for MF_TimeLerp are the StartTime and TimeDirection. StartTime is a scalar parameter, and is set by the blueprint (Game Time in Seconds) when the event is fired. Time Direction is a value between 0 and 1 and controls whether the animation should play forwards (1) or in reverse (0).

M_Interaction


Download M_Interaction material node graph

This is a simple material just for demonstration, which will use the 0-1 alpha from MF_TimeLerp to drive the transition from Colour0 to Colour1.

BP_Interaction


Download BP_Interaction blueprint node graph

Finally, this blueprint simply takes the player input through keyboard, and fires events when keys U and I are pressed. Both keys will set the material scalar parameter StartTime to the game seconds. U will set the material scalar parameter TimeDirection to 0, and I will set it to 1. So U and I are basically telling the material to play the animation backwards and forwards, respectively.

In the blueprint, I created a sphere and set its material to M_Interaction.

Result

Thanks for reading! If you have any feedback, please email me. If you liked it, please consider supporting me by buying my flipbook maker tool:
Get Flipbook Texture Tool for Windows

More

Previous

Triggering events between actors in Unreal Engine

Next

Advanced MatCap Material

Leave a Reply

Your email address will not be published. Required fields are marked *