Search Unity

setLayer in scripting not working

Discussion in 'Scripting' started by Buswolley, Jan 18, 2019.

  1. Buswolley

    Buswolley

    Joined:
    Jun 18, 2018
    Posts:
    5
    What: adjusting a gameObject's layer property, using
    gameObject.layer = x


    Expected: This layer change should be reflected in the Layer dropdown in the Inspector. Cameras that are using the layer's culling mask should render based on the new value.

    Actual: The Inspector dropdown does not show the new Layer and the Camera culling for that layer does not show the object. The change is reflected in scripting (
    Debug.Log(layer)
    shows the new value).

    Unity version: 2018.2.18f1
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Code: ???
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Make sure you're not assigning LayerMask to the Layer. As those two completely different concepts.
     
  4. Buswolley

    Buswolley

    Joined:
    Jun 18, 2018
    Posts:
    5
    Code (CSharp):
    1. var layer = LayerMask.NameToLayer("World Fragment");
    2. Debug.Log(layer); // 9
    3. gameObject.layer = layer;
    4. Debug.Log(t.gameObject.layer); // also 9
    5. Debug.Break(); // gameObject shows layer 0, Default, in inspector
     
  5. Buswolley

    Buswolley

    Joined:
    Jun 18, 2018
    Posts:
    5
    Issue was my code running in the wrong component :X resolved