Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Khena_B · Apr 01, 2018 at 06:33 PM · layersdeletelayerlayermaskused

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Apr 01, 2018 at 06:37 PM 0
Share

you'd need to write a script that runs through the project folder, each scene and within each scene through each transform. if you then OR each layer mask on top of each other and finally check the bits you'll know which ones stay 0, meaning are not used.

avatar image Khena_B hexagonius · Apr 01, 2018 at 06:42 PM 0
Share

I was hoping there would be an easier way, if I decide to write the script i'll post it here as an answer, thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Cambesa · Feb 12, 2020 at 11:46 AM

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[i].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<string> layerNames = new List<string>();
         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<string> listOfKeys = layerCount.Keys.ToList();
         List<string> 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");
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Feb 12, 2020 at 12:32 PM 1
Share

While this is certainly useful, keep in $$anonymous$$d that you could have prefabs which have a different layer assigned. So you might are missing those.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

79 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

LayerMask for RayCast 1 Answer

Layermask (raycast) wont work... 4 Answers

How to create User layer that acts like the "Ignore Raycast" layer? 1 Answer

OverlapSphere doesn't detect colliders 1 Answer

Physics2D.CircleCast produces no result whenever a layer mask is specified 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges