Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Change the layer of a cloned gameObject?

Discussion in 'Prefabs' started by Deleted User, Apr 13, 2023.

  1. Deleted User

    Deleted User

    Guest

    Hey, all.

    I was trying to use
    Code (CSharp):
    1. gameObject.layer = LayerMask.NameToLayer("whatever Layer");
    , but it gave me the error:

    A game object can only be in one layer. The layer needs to be in the range [0...31]

    How do I switch the layer of a single prefab clone?
     
  2. Peter_Olsted

    Peter_Olsted

    Unity Technologies

    Joined:
    Apr 19, 2021
    Posts:
    74
    Hi, what is the result of the call "LayerMask.NameToLayer("whatever Layer")" ?
    That error indicates the layer wasn't found.
     
  3. Deleted User

    Deleted User

    Guest

    Oh my gosh. I set the layer name as a tag. I know I did something really dumb here. Sorry.
     
    Peter_Olsted likes this.