How to change material instance parameter by Python?

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

1 Like

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)

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

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:

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')
>>>

The same question

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:

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

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

1 Like

it supposes to be unreal.load_asset(“path to tex”), editor_util.load_asset seems to report error