How to edit/add the material layers of a Material or MaterialInstanceConstant with the python api

I’m trying to dynamically edit a material instance to change the material layers in python but the documentation is not really clear how to do it.

I find a lot of different classes in the documentation that seem to be related to this such as the MaterialParameterInfo or MaterialLayersFunctions but I fail to see how I can use these class from a Material I would create from the python api.

Answering my own question for anybody who would be looking for that as well.
Currently, the API to edit the layers of a material are not exposed to the blueprints.

I created a plugin to be able to manipulate these with blueprints and python and published it on github. Feel free to copy the code:

(and here a direct link to the relevant class: UEAdvancedMaterialEditingLibrary/LayeredMaterialLibrary.h at main · njibhu/UEAdvancedMaterialEditingLibrary · GitHub )

2 Likes

Where should I locate these files.
I have tried to located the plugins at “…/Plugins/AdvancedMaterialEditingLibrary” and this one contains “AdvancedMaterialEditingLibrary.uplugin” and “Resources”
For the “Source” file it contains “AdvancedMaterialEditingLibrary” in this one we have 2 folders and 1 files, 2 folders are: “Private” and “Public”, the last one is “AdvancedMaterialEditingLibrary.Build.cs”