Know if layer is in use

I have a bunch of layers in a large project, some of which i’m not sure if they can be deleted or not, is it possible to know if those layers are being used somewhere in the project?

If anyone is interested, here’s a piece of code that logs all unused layers. You have to execute this per scene though.

    public static void CheckUsedLayers()
    {
        Debug.Log("Check used layers");
        Dictionary<string, int> layerCount = new Dictionary<string, int>();
        List<GameObject> gameObjects = FindObjectsOfType<GameObject>().ToList();

        // iterate objects and save to dictionary
        for (int i = 0; i < gameObjects.Count; ++i)
        {
            string layerName = LayerMask.LayerToName(gameObjects*.layer);*

if (layerCount.ContainsKey(layerName))
{
layerCount[layerName]++;
}
else
{
layerCount.Add(layerName, 1);
}
}

// log to console
foreach (KeyValuePair<string, int> entry in layerCount)
{
Debug.Log(entry.Key + ": " + entry.Value);
}

// unused layers
List layerNames = new List();
for (int i = 8; i <= 31; i++) //user defined layers start with layer 8 and unity supports 31 layers
{
var layerN = LayerMask.LayerToName(i); //get the name of the layer
if (layerN.Length > 0) //only add the layer if it has been named (comment this line out if you want every layer)
layerNames.Add(layerN);
}

List listOfKeys = layerCount.Keys.ToList();
List unusedLayers = layerNames.Except(listOfKeys).ToList();
string joined = string.Join(", ", unusedLayers);
Scene scene = SceneManager.GetActiveScene();
Debug.Log("Unused layers in " + scene.name + ": " + joined);

Debug.Log(“Check used layers done”);
}