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!

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.