Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

LayerMask.GetMask() vs bit-shifting

Discussion in 'Physics' started by Zephus, Jan 5, 2019.

  1. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    169
    I've seen multiple tutorials that told me to use bit-shifting to create a LayerMask, like this:
    Code (CSharp):
    1. int layerMask = 1 << LayerMask.NameToLayer("Test");
    But I just noticed there's this function called GetMask() that does the exact same thing:
    Code (CSharp):
    1. LayerMask lm = LayerMask.GetMask("Test");
    What's the difference? Why use bit-shifting (which honestly feels completely out of place in Unity) when there's this function that does it for me?
     
  2. WashingMachine

    WashingMachine

    Unity Technologies

    Joined:
    Mar 23, 2017
    Posts:
    24
    Seems to me like someone just made a method of convenience so you wouldn't have to bitshift ( which is not as easily understandable as just using a method)