Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Using a custom unsigned int for a LayerMask

Discussion in 'Scripting' started by bdsantos, Nov 8, 2019.

  1. bdsantos

    bdsantos

    Joined:
    Jul 27, 2016
    Posts:
    113
    Hello, everyone. I need some advice on how I can assign a custom Layer Mask unsigned int to a script.

    For instance, I am using the following code:
    Code (CSharp):
    1. public LayerMask hiddenMask = 4294901755;
    Sometimes this method will work, other times it gives me an error. Can somebody please help me in correctly formatting this for it to work inside Unity?
     
  2. Gambit-MSplitz

    Gambit-MSplitz

    Joined:
    May 16, 2015
    Posts:
    1,230
    You can create a LayerMask using "new LayerMask()" then assign the value to that mask. If you do it this way, it will show you the error if it is unable to do the assignment.

    LayerMasks store int values, and they cannot automatically convert your uint to an int. I'm guessing you only get this error when you use a uint value that is too large to store in an int.

    upload_2019-11-8_12-10-44.png