Unreal Python: Issues with NamedRerouteExpressions and MaterialFunctions

Hi,

I would like to write a python tool that does something with all material expressions inside of a given material.
I have some issues with two material expressions:

  1. Named Reroutes
  2. Material Functions

Named Reroutes are particular annoying, because the team is using them a lot.
My script currently runs recursively over all expressions, starting from the material inputs, but I cannot find a way to access the Named Reroute Declaration- from a given Named Reroute Usage Expression, so I cannot proceed if I stumble upon a Reroute Usage Exression.

I also seem to have no option to get just every single expression that is available in a material graph even if not connected to the material.

What are my options to support Named Reroute Expressions in my tool?

Sample code: Recursively go thru material expressions
Sample material graph: Material with reroute expressions

Thanks,
Micha

You can get all material expressions belonging to a material like this

import unreal

if __name__ == '__main__':
    # load the material
    material = unreal.EditorAssetLibrary.load_asset("/Game/Path/To/M_MyMaterial.M_MyMaterial")    

    it = unreal.ObjectIterator(unreal.MaterialExpression)

    # iterate over all loaded material expressions, append all that belong to material.
    all_material_expressions = []
    for material_expression in it:
        if material_expression.get_outer() == material:
            all_material_expressions.append(material_expression)

    # print out all expressions we stored.
    for material_expression in all_material_expressions:
        print(material_expression)

Omg, this looks really promising! Thanks in advance, I will definitely try this end of this week and give some feedback. :face_with_monocle: