Search Unity

LayerMask.GetMask() vs bit-shifting

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

  1. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    170
    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)