Download

How can I assign material to skeleton mesh with python?

Hello, I’m trying to put my material instance to 1st slot of skeletal mesh with python. After few hours of research, I did this code

import unreal
sm_asset = unreal.load_asset('/Game/Meshes/Bob')
mi_asset = '/Game/Materials/mi_head'
unreal.SkeletalMesh.materials = [unreal.SkeletalMaterial(material_interface=mi_asset, material_slot_name='mat_head', uv_channel_data=unreal.MeshUVChannelInfo())]

but I get this error

LogPython: Error: Traceback (most recent call last):
LogPython: Error:   File "<string>", line 4, in <module>
LogPython: Error: TypeError: SkeletalMaterial: Failed to convert type 'str' to property 'MaterialInterface' (ObjectProperty) for attribute 'material_interface' on 'SkeletalMaterial'
LogPython: Error:   TypeError: NativizeProperty: Cannot nativize 'str' as 'MaterialInterface' (ObjectProperty)
LogPython: Error:     TypeError: NativizeObject: Cannot nativize 'str' as 'Object' (allowed Class type: 'MaterialInterface')

All info about how can I add materials to skeletal mesh is outdated :frowning:

you need to unreal.load_asset(mi_asset)
material_interface accept MaterialInterface type not str type