2 min read

[7/50] Duplicating Material Instances with parameter variations in Unreal

An indian art style render of a video game made in Unreal Engine. (Via Stable Diffusion)
Stable Diffusion 2.1 thinks this is "An indian art style render of a video game made in Unreal Engine."

Continuing with our theme of automation from the previous post, recently we wanted to duplicate a bunch of Static Mesh and associated Material Instance objects with different values of material parameters for each of the duplicated item. Given the sizeable number of permutations of material instance parameters and static meshes we wanted to generate, doing it manually was turning out to be tedious, time-consuming and error prone process and we decided to use Editor Utility tools to semi-automate the same.

Specifically, we created an Editor Utility Blueprint which allows the users to automate editor workflow via Blueprint scripting. We ended with a context menu action that our designers and artists could use to quickly duplicate the assets.

Tint variation generator accessible from the context menu of the content browser.

While the official documentation does a good job of walking through the setup process, the logic of creating the duplicates within the Blueprint script was pretty straight forward once the setup was done.

We start with the begin transaction node (so as to be able to undo any changes) and retrieve all the assets that the user has selected for duplicating with variation.

Next after doing some asset path manipulations, we use the Duplicate Asset node to create the duplicate static mesh and then we repeat the same for each material instance associated with the mesh.

And finally we set the parameters to the desired values for these material instances before committing the transaction. While this serves our immediate purpose, there is scope for making it more flexible.