A game object can only be in one layer. The layer needs to be in the range [0...31]
Individual GameObjects have layers that can be used to affect physics and rendering.
Layers are defined in the Tags and Layers Settings ( ).
Layers are not the same as Tags, and a LayerMask
does not describe a single layer.
If you're seeing this error you have either not defined the layer in the first place, haven't referenced an existing layer identically, or are using the wrong structure like a LayerMask.
Identical includes capitalisation and spaces
Define an identical layer in the Tags and Layers Settings, and either directly use the index, or use LayerMask.NameToLayer
to get the index, then assign it to the GameObject.
A LayerMask
is not the same as a layer. Do not assign a mask to the layer
property of a GameObject.
If the error still appears, ensure the console has been cleared. Then log the GameObject and its layer before you assign it to validate your logic. See logging: how-to for more information.