Is there a way to set the Interaction Layer Mask by name? Or just get a layers int value by inputting the string to a method similar to Unity’s built in LayerMask.NameToLayer and LayerMask.LayerToName?
Would also be great to have some convenience methods like AddLayer, RemoveLayer, and SetLayer and SetLayers
I’ve always hated doing the bitwise operations for layers, and considering interaction layer changing during runtime has been suggested as the solution to so many things I’m trying to do, these methods would be extremely helpful ( I have written my own extensions to do this but they are proving unreliable)
Hello again @edwon ,
We do have at least 2 of the main methods you are looking for: InteractionLayerMask.LayerToName(int layer) and InteractionLayerMask.NameToLayer(string layerName). You can find the documentation here.
Adding more convenience methods is a good idea. We’ll add it to our backlog and look into it for a future release.
For anyone who might need it, these are all the extension methods I made for dealing with InteractionLayers
the “SetLayers” method is incredibly hacky, but does the job when you want to set multiple layers
@edwon ,
Those are great extension methods. I think the SetLayer function could probably be simplified with a for loop, no?
public static InteractionLayerMask SetLayers(this InteractionLayerMask layerMask, int[] layers)
{
layerMask = 0;
for (int i = 0; i < layers.Length ; ++i)
{
layerMask = AddLayer(layerMask, layers[i]);
}
return layerMask;
}
Or something to that effect. I haven’t tested that this works as expected, but it would allow for arbitrary sizes. You may want to limit the layers.Length so it is not greater than 32 (layer mask size).