4

I am using Unity 5.5 on Ubuntu 16.10. I have a camera culling mask with a specific set of layers.

However, in the Unity editor interface, the culling mask dropdown does not display checks next to the layers I have selected. As a result, when I have too many layers selected, the field reads Mixed ..., and I can not see which layers I set the mask to use.

When I log camera.cullingMask, I get a strange integer I can not comprehend. How can I programmatically see which layers I selected in a culling mask?

1 Answers1

2

I have the same problem on Ubuntu and no solution for the check-mark-bug.

However, I'll try to explain the strange integer that you get from the property. It is a bit field, where each layer is assigned a value:

Layer name       | Layer Number | Mask value
Builtin Layer 0  |            0 | 1 << 0 =     1
Builtin Layer 1  |            1 | 1 << 1 =     2
Builtin Layer 2  |            2 | 1 << 2 =     4
Builtin Layer 3  |            3 | 1 << 3 =     8
Builtin Layer 4  |            4 | 1 << 4 =    16
Builtin Layer 5  |            5 | 1 << 5 =    32
Builtin Layer 6  |            6 | 1 << 6 =    64
Builtin Layer 7  |            7 | 1 << 7 =   128
User Layer 1 / 8 |            8 | 1 << 8 =   256
User Layer 2 / 9 |            9 | 1 << 9 =   512
...

(It seems that User Layer names may start at 1 or at 8 depending on the Unity version)

You can combine these values, for example Builtin Layer 5and User Layer 9 would result in 1 << 5 | 1 << 9 = 2^5 | 2^9 = 32 | 512 = 32 + 512 = 544.

Read more about Layer masks in the documentation.

  • Thank you for the information. However, I am still at a loss concerning my core issue: suppose I have a layermask that is set for layers 3, 5, and 7. How can I figure that out based on the camera.cullingMask property? How do I deduce the layers from the integer? Do I just have to know that 544 = 512 + 32 = 2^5 + 2^9? Is there no way to get a direct listing of the layers in a mask? Unfortunately, I have no experience with bit fields. – David Y. Stephenson Jul 31 '17 at 11:01