I have a material in my project named “No Name”. Is there a way to find if this “No Name” material is actually being used?
Hey there,
I know it’s an old thread but I wrote a small editor script doing that, as Find References In Scene give me some weird results sometimes. If anyone is interested, here you go :
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Utils.EditorExtension
{
public class MaterialChecker : Editor
{
[MenuItem("Assets/Check Material")]
private static void CheckMaterial()
{
Material matToCheck = Selection.activeObject as Material;
foreach (var renderer in FindObjectsOfType<MeshRenderer>())
{
if (renderer.sharedMaterials.Contains(matToCheck))
Debug.Log("Material used by " + renderer.transform.name, renderer.gameObject);
}
}
[MenuItem("Assets/Check Material", true)]
private static bool CheckMaterialValidation()
{
return Selection.activeObject is Material;
}
}
}
It can easily be extended for any type of Asset you want to check, hope that helps !
This was just the thing I needed. I thought I would add the code changes here (so true parameter as per above) and my addition when a material is not found. Older found messages were not being cleared.
var matFound = false;
foreach (var renderer in FindObjectsOfType<MeshRenderer>(true))
{
if (renderer.sharedMaterials.Contains(matToCheck))
{
Debug.Log($"Material used by {renderer.transform.name} {renderer.gameObject}");
matFound = true;
}
}
if(!matFound)
Debug.Log("Material not used");