Skip to main content
Tweeted twitter.com/StackGameDev/status/791675517552427008
deleted 113 characters in body; edited tags; edited title
Source Link
user1430
user1430

Why must wedo Unity layer masks need to use bit shifting for Unity Layer masks?

I've finally figured out why my layer masks for my ground collision code weren't working. I was using NameToLayer()NameToLayer() to get the layer I needed, but Layermaskslayer masks use bit shifting to actually set the layer mask value. This is extremely unusual and I don't see any reason why this isn't handled in the code behind. Why do we have to use code like this:

mask = 1 << LayerMask.NameToLayer("Default"); 

mask = 1 << LayerMask.NameToLayer("Default"); when something like this:

mask = LayerMask.NameToLayer("Default"); 

mask = LayerMask.NameToLayer("Default"); makes more intuitive sense and works similar to the rest of the Unity API?

(Is that the right use of the term API? I don't actually know what that word means, so I've been inferring it from context.)

Why must we use bit shifting for Unity Layer masks?

I've finally figured out why my layer masks for my ground collision code weren't working. I was using NameToLayer() to get the layer I needed, but Layermasks use bit shifting to actually set the layer mask value. This is extremely unusual and I don't see any reason why this isn't handled in the code behind. Why do we have to use code like this:

mask = 1 << LayerMask.NameToLayer("Default"); when something like this:

mask = LayerMask.NameToLayer("Default"); makes more intuitive sense and works similar to the rest of the Unity API?

(Is that the right use of the term API? I don't actually know what that word means, so I've been inferring it from context.)

Why do Unity layer masks need to use bit shifting?

I've finally figured out why my layer masks for my ground collision code weren't working. I was using NameToLayer() to get the layer I needed, but layer masks use bit shifting to actually set the layer mask value. This is extremely unusual and I don't see any reason why this isn't handled in the code behind. Why do we have to use code like this:

mask = 1 << LayerMask.NameToLayer("Default"); 

when something like this:

mask = LayerMask.NameToLayer("Default"); 

makes more intuitive sense and works similar to the rest of the Unity API?

Source Link
Space Ostrich
  • 227
  • 1
  • 3
  • 7

Why must we use bit shifting for Unity Layer masks?

I've finally figured out why my layer masks for my ground collision code weren't working. I was using NameToLayer() to get the layer I needed, but Layermasks use bit shifting to actually set the layer mask value. This is extremely unusual and I don't see any reason why this isn't handled in the code behind. Why do we have to use code like this:

mask = 1 << LayerMask.NameToLayer("Default"); when something like this:

mask = LayerMask.NameToLayer("Default"); makes more intuitive sense and works similar to the rest of the Unity API?

(Is that the right use of the term API? I don't actually know what that word means, so I've been inferring it from context.)