Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by runonthespot · Feb 20, 2012 at 05:21 PM · runtimelayersdynamic

Dynamically add layers

Is it possible to create layers dynamically in Unity, and is there a limit?

Basically, I'm using the DepthMask shader from the unity wiki, and to create multiple layers, am basically forced to create a camera and associated culling layer for each mask "layer".

I'm trying to come up with a generic solution to be able to add this to any project without disturbing existing layers, but am hitting a brick wall. Ideally I'd like to be able to see what user layers are in use, and dynamically create higher layers (at runtime, but if possible at design time, that's okay too.) and assign various objects to those layers.

Any hints at how this might be achieved would be very welcome!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Berenger · Feb 20, 2012 at 07:59 PM

I don't think you can do that by script. However, it's just a list of names, so you can do your own. The layer would then be 1 << (myLayers.IndexOf( "Coconut" ) + nbUnityLayers; You'll have to manually enter nbUnityLayers though. I think the only difference will be that unity won't be able to display the layer's name in the inspector.

Comment
Add comment · Show 4 · 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 runonthespot · Feb 21, 2012 at 09:00 AM 0
Share

Just thinking through the way layermasks work, and I guess it's obvious that because it's stored as an integer, the implication is that there are a maximum of 31 layers in Unity? Given that there are only 32-bit integers, e.g. 31 bits to play with?

avatar image syclamoth · Feb 21, 2012 at 09:03 AM 3
Share

Yes, that's right. Only 31 layers.

avatar image 1337GameDev · Jul 26, 2014 at 09:24 PM 0
Share

isn't (2^31)-1 much larger than 31, actually equals 2147483647...

im sure 31 is 2^5-1. And only 5 bits (with one bit for sign).

avatar image Eric5h5 · Feb 02, 2015 at 08:49 PM 0
Share

32 layers, not 31. Each layer needs its own bit—this is a layermask, not an integer—so it's not possible to have more than 32, as long as you're using a 32-bit number.

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

7 People are following this question.

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

Related Questions

Export objects to a .3DS file at runtime 1 Answer

Platforms lose their frictionless property after dynamic layer change 0 Answers

How to dynamically change the shape of a mesh during runtime? 1 Answer

Dynamic Layer Switching Performance 0 Answers

Dynamicaly Creating A Plane With A JPG Material ... 2 Answers


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