using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using UnityEngine.SceneManagement; public class ObjectLayerChecker : MonoBehaviour { private void Awake() { CheckUsedLayers(); } public static void CheckUsedLayers() { Debug.Log("Check used layers"); Dictionary layerCount = new Dictionary(); List gameObjects = FindObjectsOfType().ToList(); // iterate objects and save to dictionary for (int i = 0; i < gameObjects.Count; ++i) { string layerName = LayerMask.LayerToName(gameObjects[i].layer); if (layerCount.ContainsKey(layerName)) { layerCount[layerName]++; } else { layerCount.Add(layerName, 1); } } // log to console foreach (KeyValuePair 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"); } }