I’m attempting to make a public List placeableLayers in my script where I can choose the layers I want to be in the list via the inspector.
I set up my list in the inspector like normal (I can choose from the list of available layermasks and put them in the list), but when the code runs and compares the LayerMask’s ‘value’ field against a gameObject.layer item, the LayerMask’s value (from the List) has bizarre out of bounds layermask values, like 2048 and 4098 (powers of 2, interestingly enough).
Am I misunderstanding how to compare layer masks?
The code that does the comparison:
// placeableLayerMasks is a List<LayerMask> declared public for this class, filled in via the inspector with valid LayerMasks.
// is this object configured with a layer that matches the layer we 'hit' with our raycast down?
private bool IsLayerPlacable(int layer) // 'int layer' is the result of gameObject.layer
foreach (LayerMask placeableLayer in placeableLayerMasks)
{
Debug.Log("Comparing " + placeableLayer.value + " with " + layer);
if (layer == placeableLayer.value) // TODO these are broken playableLayer.value is garbage??
{
Debug.Log("TRUEEEE");
return true;
}
}
placeableLayer.value is not a valid layer value, even though I’ve configured these via the inspector (and when running, viewing this list in the inspector still shows the appropriate values).