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

**URL:** <https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850>\
**Category:** Editor Scripting\
**Tags:** Python, unreal-engine, UE5-0, question, UE4-27\
**Created:** [May 6, 2022, 10:13pm UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850 "2022-05-06T22:13:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Njibhu](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/njibhu/32/476805_2.png) [@Njibhu](https://forums.unrealengine.com/u/Njibhu)\
**Post date:** [May 6, 2022, 10:13pm UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850/1 "2022-05-06T22:13:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Njibhu](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/njibhu/32/476805_2.png) [@Njibhu](https://forums.unrealengine.com/u/Njibhu)\
**Post date:** [May 8, 2022, 8:40pm UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850/2 "2022-05-08T20:40:48Z")

</div>

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:

> **[GitHub - njibhu/UEAdvancedMaterialEditingLibrary](https://github.com/njibhu/UEAdvancedMaterialEditingLibrary)**
>
> Contribute to njibhu/UEAdvancedMaterialEditingLibrary development by creating an account on GitHub.

(and here a direct link to the relevant class: [UEAdvancedMaterialEditingLibrary/LayeredMaterialLibrary.h at main · njibhu/UEAdvancedMaterialEditingLibrary · GitHub](https://github.com/njibhu/UEAdvancedMaterialEditingLibrary/blob/main/Source/AdvancedMaterialEditingLibrary/Public/LayeredMaterialLibrary.h) )

---

<div class="post-metadata">

**Author:** ![Pilo\_Gustinman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pilo\_Gustinman](https://forums.unrealengine.com/u/Pilo_Gustinman)\
**Post date:** [July 20, 2023, 12:50pm UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850/3 "2023-07-20T12:50:51Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![dpotuznik](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dpotuznik](https://forums.unrealengine.com/u/dpotuznik)\
**Post date:** [July 30, 2024, 12:05pm UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850/4 "2024-07-30T12:05:13Z")

</div>

Hi Njibhu,

i big thank you for this nice +C+ class

I put here just a simple class inherited from yours to have automatic completion

have a nice day everyone

```auto
import unreal

class LayeredMaterialLibrary:
    
    @staticmethod
    def get_layer_count(instance):
        return unreal.LayeredMaterialLibrary.get_layer_count(instance)

    @staticmethod
    def add_material_layer(instance):
        return unreal.LayeredMaterialLibrary.add_material_layer(instance)

    @staticmethod
    def is_layered_material(instance):
        return unreal.LayeredMaterialLibrary.is_layered_material(instance)

    @staticmethod
    def assign_layer_material(instance, layer_index, new_layer_function):
        return unreal.LayeredMaterialLibrary.assign_layer_material(instance, layer_index, new_layer_function)

    @staticmethod
    def assign_blend_layer(instance, layer_index, new_blend_layer_function):
        return unreal.LayeredMaterialLibrary.assign_blend_layer(instance, layer_index, new_blend_layer_function)

    @staticmethod
    def get_layered_material_scalar_parameter_value(instance, parameter_name, layer_index):
        return unreal.LayeredMaterialLibrary.get_layered_material_scalar_parameter_value(instance, parameter_name, layer_index)

    @staticmethod
    def set_layered_material_scalar_parameter_value(instance, parameter_name, layer_index, value):
        return unreal.LayeredMaterialLibrary.set_layered_material_scalar_parameter_value(instance, parameter_name, layer_index, value)

    @staticmethod
    def get_layered_material_static_switch_parameter_value(instance, parameter_name, layer_index):
        return unreal.LayeredMaterialLibrary.get_layered_material_static_switch_parameter_value(instance, parameter_name, layer_index)

    @staticmethod
    def set_layered_material_static_switch_parameter_value(instance, parameter_name, layer_index, value):
       return unreal.LayeredMaterialLibrary.set_layered_material_static_switch_parameter_value(instance, parameter_name, layer_index, value)

    @staticmethod
    def get_layered_material_texture_parameter_value(instance, parameter_name, layer_index):
        return unreal.LayeredMaterialLibrary.get_layered_material_texture_parameter_value(instance, parameter_name, layer_index)

    @staticmethod
    def set_layered_material_texture_parameter_value(instance, parameter_name, layer_index, value):
        return unreal.LayeredMaterialLibrary.set_layered_material_texture_parameter_value(instance, parameter_name, layer_index, value)

# Example usage
if __name__ == " __main__":
    instance = unreal.load_object(None, '/Game/AP_MaterialLibrary/CommonMaterial/CommonLayer/testPython')
    new_layer_function = unreal.load_object(None, '/Game/AP_MaterialLibrary/LayerMaterial/ML_Master/ML_PLANAR_LAYER')
    new_blend_layer_function = unreal.load_object(None, '/Game/AP_MaterialLibrary/LayerMaterial/ML_Blend/MLB_PlanarAngleHeightVertexRadialMaskAutoAxe')
    parameter_name = 'Metallic'
    layer_index = 0
    value = .5

    #LayeredMaterialLibrary.refresh_editor_material_instance(instance)
    print(instance)
    print(LayeredMaterialLibrary.get_layer_count(instance))
    LayeredMaterialLibrary.add_material_layer(instance)
    print(LayeredMaterialLibrary.is_layered_material(instance))
    LayeredMaterialLibrary.assign_layer_material(instance, layer_index, new_layer_function)
    layer_index = 1
    LayeredMaterialLibrary.assign_layer_material(instance, layer_index, new_layer_function)
    LayeredMaterialLibrary.assign_blend_layer(instance, layer_index, new_blend_layer_function)
    print(LayeredMaterialLibrary.get_layered_material_scalar_parameter_value(instance, parameter_name, layer_index))
    LayeredMaterialLibrary.set_layered_material_scalar_parameter_value(instance, parameter_name, layer_index, value)
    parameter_name = 'Normal Map ?'
    print(LayeredMaterialLibrary.get_layered_material_static_switch_parameter_value(instance, parameter_name, layer_index))
    LayeredMaterialLibrary.set_layered_material_static_switch_parameter_value(instance, parameter_name, layer_index, True)
    parameter_name = 'Normal_Map'
    print(LayeredMaterialLibrary.get_layered_material_texture_parameter_value(instance, parameter_name, layer_index))
    #LayeredMaterialLibrary.set_layered_material_texture_parameter_value(instance, parameter_name, layer_index, unreal.load_object(None, '/Game/Path/To/Your/Texture'))
 

```

---

<div class="post-metadata">

**Author:** ![EJaworenko1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ejaworenko1/32/575974_2.png) [@EJaworenko1](https://forums.unrealengine.com/u/EJaworenko1)\
**Post date:** [December 11, 2024, 1:32am UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850/5 "2024-12-11T01:32:38Z")

</div>

For other people who find this forum post, I extended @Njibhu’s plugin to support more different kinds of parameters to adjust + material layer blend parameters as well. I also created documentation hosted online and under Releases you can find builds for UE versions from 5.1 to 5.5. [GitHub - EJaworenko/UEAdvancedMaterialEditingLibrary: An Unreal Engine 5 plugin that enables programmatic editing of material layers and blend parameters through both Python and Blueprint interfaces.](https://github.com/EJaworenko/UEAdvancedMaterialEditingLibrary)

---

<div class="post-metadata">

**Author:** ![Anonymous\_851cefe1a62f30c2338e18ecd74f822a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_851cefe1a62f30c2338e18ecd74f822a](https://forums.unrealengine.com/u/Anonymous_851cefe1a62f30c2338e18ecd74f822a)\
**Post date:** [December 12, 2024, 7:28am UTC](https://forums.unrealengine.com/t/how-to-edit-add-the-material-layers-of-a-material-or-materialinstanceconstant-with-the-python-api/550850/6 "2024-12-12T07:28:28Z")

</div>

cool
