Is there a way using the Python API to list all the nodes for a Material and what files is attached to each node?

For example, if I wished to write a Python script that lists the Base Color, Metallic, Specular, Roughness, Anistopy etc. nodes and what textures are attached to each node, would this be possible and if so how would I go about it?

I am already aware that unreal.AssetRegistryHelpers.get_asset_registry().get_dependencies(package_path, options) will give me a list of dependent textures, but it gives me no context as to which nodes each texture file is connected to.

I don’t think there’s a direct way to do that right now. The “MaterialEditingLibrary” provides some functions, but not enough. We need to create some blueprint callable function ourselves. Just like below. I will add this to my plugin in the next version. Python Editor Extended API - TAPython

Another way is to export the material, then use python to parse the exported “.t3d” or “.copy” file, which contains the full information of the material.

1 Like

If you have the Material loaded, like

material = unreal.EditorAssetLibrary.load_asset(<asset_path>)

You can then run an ObjectIterator

it = unreal.ObjectIterator()
for x in it:
  if isinstance(x, unreal.MaterialExpression) or x.get_path_name().startswith(<asset_path>)):
    print(x)

Which will print all nodes in your loaded material

The MaterialEdititingLibrary should then have methods you can use to get how nodes are connected

5 Likes

@chpsemail Did you managed to add log_material_tree to your plugin? It would be insanely useful to me.