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!
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?
– runonthespotYes, that's right. Only 31 layers.
– syclamothisn'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).
– 1337GameDev32 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.
– Eric5h5