Search Unity

Using a custom unsigned int for a LayerMask

Discussion in 'Scripting' started by Deleted User, Nov 8, 2019.

  1. Deleted User

    Deleted User

    Guest

    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. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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