How to Connect Nodes in Material Editor Using Python API?

I’ve been trying to automate some of the import processes of my Unreal project and I would like to create Materials using the Python API. I’ve been able to generate various Material Expressions but I haven’t been able to connect my output to the CustomizedUV0 slot of the Material. Any thoughts?

Here is my code so far.


import unreal

asset_tool = unreal.AssetToolsHelpers.get_asset_tools()
new_material = asset_tool.create_asset(asset_name="M_Test", package_path="/Game", asset_class=unreal.Material,
factory=unreal.MaterialFactoryNew())
new_material.set_editor_property('num_customized_u_vs', 1)
texture = unreal.load_asset('/Game/Procedural_Ecosystem/Textures/T_cliff_a_n.T_cliff_a_n')
create_expression = unreal.MaterialEditingLibrary.create_material_expression

texture_sample = create_expression(new_material, unreal.MaterialExpressionTextureSample, -800, 0)
texture_sample.texture = texture
print("Property: " + str(texture_sample.get_editor_property('texture')))

scalar_param = create_expression(new_material, unreal.MaterialExpressionScalarParameter, -800, 500)
scalar_param.set_editor_property('parameter_name', 'Zoom Multiplier')
scalar_param.set_editor_property('default_value', 2000.0)
print("Property: " + str(scalar_param.get_editor_property('default_value')))

division = create_expression(new_material, unreal.MaterialExpressionDivide, -500, 400)
texture_coord = create_expression(new_material, unreal.MaterialExpressionTextureCoordinate, -800, 400)

unreal.MaterialEditingLibrary.connect_material_expressions(texture_coord, '', division, 'a')
unreal.MaterialEditingLibrary.connect_material_expressions(scalar_param, '', division, 'b')
unreal.MaterialEditingLibrary.connect_material_property(texture_sample, '', unreal.MaterialProperty.MP_EMISSIVE_COLOR)
unreal.MaterialEditingLibrary.connect_material_property(division, '', unreal.MaterialProperty.MP_CUSTOMIZED_UV_0)