8

There are a few materials in a blend file I have that I don't think are necessary in the file. However, none of these materials show up in orphan data. I know something is using these materials because if I add the material to another object, it will show a 2 in the material slot (for those who don't know, this means that 2 items are using the material. One of these is the object I plugged it into and the other one is what I want to figure out.) I checked all the meshes in the file and couldn't find a single one that was using the materials I think are not needed. None of these materials have any fake users either. How can I find what is using the material so I can be sure that I can delete it?

Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 3
    Hard to say without seeing the file, but a material can be referenced in several places, for instance in the render passes override or in geometry nodes – Gorgious Jul 15 '21 at 06:32
  • 1
    To be sure it is not assigned to anything: if you're choosing a material slot on an object and use the dropdown menu to assign a material, is the one in question there marked with a 0 in front of the name? If not, then it's assigned to something, whatever that might be (as @Gorgious pointed out, it's not necessarily a mesh object). – Gordon Brinkmann Jul 15 '21 at 09:23
  • @GordonBrinkmann There is no 0 in front of the material –  Jul 20 '21 at 23:09
  • Then it's most likely assigned to something... – Gordon Brinkmann Jul 20 '21 at 23:47
  • @GordonBrinkmann How can I figure out what it is? I checked all the meshes and couldn't find any that were using the material. –  Jul 21 '21 at 01:16
  • I would try to find it in the Outliner under a Display Mode like Data API maybe... expand all hierarchy and try to filter with the name... but I don't know. Hard to tell without the original file what to look for. Maybe it's completely easy to find with the correct intention. Without the file I can only give you tell you to look everywhere. – Gordon Brinkmann Jul 21 '21 at 08:01

1 Answers1

10

This appears to be the same question as How to find out what is using an image except that it's for materials rather than images. The first answer there, in the form of a python script, will solve this as well; by replacing the image bits with material bits.

Copy and paste script block into text editor and run it. Output written to system console:

import bpy
from bpy.types import bpy_prop_collection

def search(ID): def users(col): ret = tuple(repr(o) for o in col if o.user_of_id(ID)) return ret if ret else None return filter(None, ( users(getattr(bpy.data, p)) for p in dir(bpy.data) if isinstance( getattr(bpy.data, p, None), bpy_prop_collection )
) )

report all materials and their users in the console

for mat in bpy.data.materials: print (20*"-") print(repr(mat)) print("Users:", mat.users)
for users in search(mat): print(users)

Console output (default scene):

--------------------
bpy.data.materials['Dots Stroke']
Users: 2
("bpy.data.brushes['Airbrush']", "bpy.data.brushes['Pencil Soft']")
--------------------
bpy.data.materials['Material']
Users: 1
("bpy.data.meshes['Cube']",)

Credit goes to @batFINGER, see How to find out what is using an image in a blend file

brockmann
  • 12,613
  • 4
  • 50
  • 93
Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 1
    @brockman deserves half the bounty for updating the python to use mat.* – Marty Fouts Jul 21 '21 at 21:34
  • No problem, was dead easy to adapt it. – brockmann Jul 21 '21 at 21:35
  • lol, thought this was the question I answered. Cheers for the cite. Appreciate the feedback. – batFINGER Jul 23 '21 at 14:34
  • Any idea how to adapt this to search for actions assigned to an armature even if they aren't the current linked action? I've created 8 actions on one rig and I want to return all those action names as a list. – Tyler Feb 14 '23 at 22:35
  • No luck with bpy.context.active_object.user_of_id(bpy.data.actions['Mixamo_MocapGuy_Idle Neutral 1']). It also only works for linked actions. – Tyler Feb 14 '23 at 22:48
  • Is this impossible because blender shares data blocks by default? So after unlinking an action it has no metadata that says it was created on a specific rig? – Tyler Feb 15 '23 at 00:03