# How to change material instance parameter by Python?

**URL:** <https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077>\
**Category:** Editor Scripting\
**Tags:** Python, unreal-engine, question, CPP\
**Created:** [August 2, 2020, 7:18pm UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077 "2020-08-02T19:18:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skell\_VR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Skell\_VR](https://forums.unrealengine.com/u/Skell_VR)\
**Post date:** [August 2, 2020, 7:18pm UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077/1 "2020-08-02T19:18:58Z")

</div>

How to change material instance parameter by Python?  
I want to when I excecute Python,my material instance parameter can auto change

## This is my python code but it’s not work

import unreal

@unreal.uclass()  
class GetMaterialInstanceConstant(unreal.MaterialInstanceConstant):  
pass  
@unreal.uclass()  
class GetEditorProperty(unreal.MaterialInstanceConstant):  
pass  
@unreal.uclass()  
class GetParameterInfo(unreal.MaterialInterface):  
pass

MaterialParameterInfo=GetParameterInfo  
print(MaterialParameterInfo)

Diffuse\_Main\_Map\_Brightness=True

def get\_scalar\_parameter\_value(Diffuse\_Main\_Map\_Brightness):  
return float(2.0)

* * *

 ![308947-擷取.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/c/b0ca479d933e43fa9ab72312429318831b82f975.png)

---

<div class="post-metadata">

**Author:** ![knapeczadam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@knapeczadam](https://forums.unrealengine.com/u/knapeczadam)\
**Post date:** [August 4, 2020, 10:51pm UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077/2 "2020-08-04T22:51:26Z")

</div>

import unreal

```
editor_util = unreal.EditorUtilityLibrary()
material_util = unreal.MaterialEditingLibrary()

selected_assets = editor_util.get_selected_assets()

# if len(selected_assets) == 1:
    # selected_assets[0] ...

for asset in selected_assets:
    if asset.get_class().get_name() == "MaterialInstanceConstant":
        material_util.set_material_instance_scalar_parameter_value(asset, "Diffuse Main Map Brightness", 42)
```

---

<div class="post-metadata">

**Author:** ![dtgdsgroup](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dtgdsgroup](https://forums.unrealengine.com/u/dtgdsgroup)\
**Post date:** [July 14, 2023, 1:10pm UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077/3 "2023-07-14T13:10:28Z")

</div>

Is there a way to change a 2dtexture parameter? EG:

```auto
editor_util = unreal.EditorUtilityLibrary()
material_util = unreal.MaterialEditingLibrary()

selected_assets = editor_util.get_selected_assets()
# Texture 
flipbookTexture = "/Game/Content/Flipbook/14x11"

for asset in selected_assets:
    if asset.get_class().get_name() == "MaterialInstanceConstant":
        material_util.set_material_instance_texture_parameter_value(asset, "FlipBookSprite", flipbookTexture)

```

Which gives this error:

```auto
Traceback (most recent call last):
  File "c:\Users\DirkTeucher\OneDrive - GDS Group\Desktop\Python Unreal Engine\Change Parameter.py:38", line 38, in <module>
TypeError: MaterialEditingLibrary: Failed to convert parameter 'value' when calling function 'MaterialEditingLibrary.SetMaterialInstanceTextureParameterValue' on 'Default__MaterialEditingLibrary'
  TypeError: NativizeProperty: Cannot nativize 'str' as 'Value' (ObjectProperty)
    TypeError: NativizeObject: Cannot nativize 'str' as 'Object' (allowed Class type: 'Texture')
>>>

```

 ![material_instance](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/5/f/f5f2766e6fa3bc7f3ae6a3a38fe82b44345f32c7.png)

---

<div class="post-metadata">

**Author:** ![9Evgeny9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@9Evgeny9](https://forums.unrealengine.com/u/9Evgeny9)\
**Post date:** [August 18, 2023, 3:40pm UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077/4 "2023-08-18T15:40:53Z")

</div>

> [@dtgdsgroup](#):
>
> Is there a way to change a 2dtexture parameter? EG:

The same question

---

<div class="post-metadata">

**Author:** ![BojanglesTheLess](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BojanglesTheLess](https://forums.unrealengine.com/u/BojanglesTheLess)\
**Post date:** [October 17, 2023, 3:20pm UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077/5 "2023-10-17T15:20:19Z")

</div>

right now `flipbookTexture` is the path, not the asset itself. That’s why it’s saying it can’t convert a `str`

you need to change it to this:

```auto
flipbookTexture = editor_util.load_asset("/Game/Content/Flipbook/14x11")

```

your code helped me solve my issue, hopefully this helps you!

---

<div class="post-metadata">

**Author:** ![jiaqiXQQ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jiaqiXQQ](https://forums.unrealengine.com/u/jiaqiXQQ)\
**Post date:** [November 19, 2024, 6:30am UTC](https://forums.unrealengine.com/t/how-to-change-material-instance-parameter-by-python/469077/6 "2024-11-19T06:30:57Z")

</div>

it supposes to be unreal.load\_asset(“path to tex”), editor\_util.load\_asset seems to report error
