I'm trying to write some code to clean up duplicate materials after some imports but having a bit of trouble with comparing them.

I have used chatGPT to try and progress but I fear as the latest version it knows about for blender is 2.8 it might not have the latest method to do it.

I have two materials that are exactly the same in terms of textures and shader properties "default" & "default.001", I'm trying to compare them using the following piece of code

 if material.node_tree == other_material.node_tree:

Unfortunately the code does not say they are the equal, am I doing the code wrong? or is it simply that the name of the material is included in the node_tree and that means they are not equal? (As in default & default.001)

I'd appreciate any help anyone could give me on this, I'm still rather new at blender python and find the documentation rather confusing!

  • $\begingroup$ I'm afraid equality in this case doesn't test if their nodes are the same, this would be an interpretation on the user's part. Equality tests if they are actually the same underlying object, that points to the same location in memory, which is not the case since they are different objects, that just happen to have duplicated data. Two different materials can't share the same node tree, unless you specifically use a node group with the same internal data. what you want to do I think is create your own equality checker and iterate all nodes and links to check if they're the same $\endgroup$
    – Gorgious
    Mar 20, 2023 at 8:51


You must log in to answer this question.

Browse other questions tagged .