How To Remove LayerMask (Bit Operator)

Hi there,
I was recently introduced to bit operators and specifically how to add a layer mask after run time to a variable.

faceLayerMask = faceLayerMask | (1<<10);

but I can not for the life of me, figure out how to remove the added layer. Various attempts have failed.

Thanks

try

faceLayerMask ^= (1<<10);

the ^= operator returns true only if one and only one of both bits being compared is equal to 1

4 Likes

That did it.
Thanks.
!!!::)()(

1 Like

Doesn’t that mean that you could accidentally add the layer to the mask if doens’t contain the layer already ?
My guess for strictly removing a layer from a mask would have been:
faceLayerMask &= ~(1<<10);

(Though I’m also new to bit operators so correct me if I’m wrong, I literally just discovered the ~ operator while checking whether ! would do what I wanted).

1 Like

It’s an old post, but I believe the &= ~(1 << shift) is correct. :slight_smile:

2 Likes