[EDITOR] How to select multiple layers in the Inspector?

Hello!

I’m making an prefab where I want to be able to set which layers the prefab will collide with. The easiest thing that comes to mind is to ask for an array of integers that correspond with the layer indices.

But that’s not exactly clear to level designers and artists. I’m looking at the culling masks of a Camera and they have a super nice drop down that allows me to see the layer names and check off which layers I want the camera to display. Check out the screenshot.

How would I go about making the same kind of drop down for my own custom inspectors?

  • Displays Layer Names.
  • Allows me to check off multiple layer names.

This might be what you’re looking for: Unity - Scripting API: LayerMask

I use this class to create a drop-down display of layers so I can select which layers I want my script to raycast against.

1 Like

Layermask is the class to store the data he’s talking about, but I don’t know if there’s a function to do this in custom Inspectors. There’s EditorGUILayout.LayerField (which seems to only choose one thing), and .MaskField (which does allow multiple selection, but you’d have to deconstruct and rebuild the LayerMask from that yourself).

HOWEVER, if you don’t have a custom inspector, a public LayerMask should pop up with that dropdown in the inspector. That probably also means that you can use the serialized property field in a custom inspector to do the same, I think.

1 Like

I didn’t realize that LayerMask could be used in the inspector like that. And for custom inspectors I’m sure I can deconstruct and rebuild the LayerMask like that if I need to pretty easily.

Thanks for the help!