Returns the array of node names that the material has

Hi again @TumHardy!

I wanted to follow up on this again for you or anyone else who stumbles onto this thread. After needing to do the same thing, I’ve learned a lot.

To start off, I couldn’t find a way to search for a specific material expression within a material. Maybe there is a way to do this, but I didn’t see anything. Instead, you need to load the material and get all of the material expressions. I couldn’t find a way to differentiate between material expressions of the same type, so the method I used was to get their input parameters and their values to check if it was the one I was looking for.

Now, this entire process is a lot of for loops with a large amount of inputs. I simplified this down as much as possible by only searching for a material once then saving it to an array if it contained the node I needed, so I only needed to find the material once when iterating over a bunch of meshes. I also made sure I was only getting the input names and values of the specific node type I was searching for, so I didn’t need to get all of the input parameters of every material expression in the material.

In the end, this is what my setup looked like:



With this being the logic of my main python script that gets every material expression:

import unreal

if name == ‘main’:
# load the material
material = unreal.EditorAssetLibrary.load_asset(matpath)

it = unreal.ObjectIterator(unreal.MaterialExpression)

ocl_exp = []

# 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:
    ocl_exp.append(material_expression)