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

Do not use layer 31?

Discussion in 'Scripting' started by lordofduct, Apr 12, 2018.

  1. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    So I was just working on something and I pulled the the layer's documentation page.

    And at the bottom I noticed something I never seen in the 7+ years I've been using Unity:

    https://docs.unity3d.com/Manual/Layers.html

    Wat?

    OK... 1) Unity has 8 layers already reserved, only 5 of which are named, why not use one of the other 3 it reserved?

    2) What is it referring to? What is the Editor Preview's window mechanics? In what way could they clash?

    See... layers in unity are multi-purpose. Not only are they used for physics, but for lighting, and for camera rendering.

    As a result... I tend to use different ranges to organize out what the layer pertains to. As a result I might invert my order from 31 back for a sub group of layers.

    Never realizing unity suggests not to use layer 31.

    ...

    Now up until now, I haven't really any known issues with this so called potential 'clash'... but it leaves me scratching my head. Do clashes exist that I'm completely unaware of and I just assume them to be weird unity quarks, and why in god's name is this only mentioned passingly in this single piece of documentation rather than well... as previously stated... the 8 other reserved layers!!!?

    ...

    Anyways... wondering if anyone else had noticed this before and their opinions on the matter. Or have answers to questions 1 and 2.
     
    Shushustorm and rakkarage like this.
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I use 31 all the time. I have no idea what raving nonsense this is. If Unity didn't want us to use 31, it would be a huge fail letting us use it with impunity if it were harmful.

    As it's just note, I suspect some UI stuff renders using that layer so an editor preview window might draw random scene stuff, dunno. Guessing.

    Have blindly continued to use it with no ill effects.
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Never used that many layers, myself.

    Now I'm curious what the potential clash would mean. =)

    I tried to look this up for more info, but the only thing I found was an issue report flagged as "Won't fix".
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    So I answered my own question of what they meant by Editor Preview's window mechanics and in what way they clash.

    I was just talking to my artist about it and how weird it is... and he's like "wait, which layer is 31?", "floor", "floor? OMG! I saw this this morning!!!"

    Turns out it was a quark that we just been looking over.

    So what it is, is the 'preview' window/icons for stuff in your asset folder. I guess how Unity renders these is they draw the models on layer 31. So if anything is on that layer... it will show up when it gets drawn.

    Like this:
    FloorLayerBug.jpg

    Note, the preview window in the lower right, and the preview icons in the assets folder. It's supposed to be a gun, but there's this weird grey nonsense in there too.

    Well, it's the pile of hats from in the scene!

    That pile of hats is on layer 31 because my artist wanted to treat it as 'floor', and the collider and visuals are on the same GameObject.
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ah interesting. I just left a comment on the Manual's page at the bottom (along with suggesting that the code samples use nice formatting*). :)

    So it's a nuisance for the preview, but other than that, no real harm is done. Good to know on both counts.
     
    lordofduct likes this.
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,143
    That's good to know. I don't think we've gone that high on layers, but maybe one day!
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,194
    ... zombie harlot?


    As far as I understand, all things that you can preview - models, animations, etc., are previewed by instantiating a HideAndDontSave copy at the origin, on layer 31, with a HideAndDontSave camera looking at only layer 31. So you can use the layer for stuff, but it means that if you have something around the origin on that layer, it'll show up in your animation previews and whatnot.

    By the way, if anyone has figured out how to make custom stuff show in the preview window, I'd really love to know, because the only writeup I've found is from Unity 4 and in Japanese.
     
  8. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Just stumbled over this in Unity 2022.1.22f1. Tried using layer 31 on a test object, which promptly became invisible. It was marked as visible in the top-right layers visibility list, the camera, and the opaque and transparent layers in the URP asset. Switched to layer 30, and the object appeared. If Unity is going to reserve a layer for internal use, it shouldn't be writable.
     
    Shushustorm likes this.
  9. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,861
    Never knew this, but I just had to try adding a directional light to Layer 31 just to see if it will finally make my preview icons less moribund and lackluster. No visible effect that I can see.
     
    PraetorBlue likes this.
  10. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51
    2022.2.17f1 Layer 31 if used causes Exceptions upon pulling up any Layer ComboBox like on the Camera component.
    Already reported ..but i have no response yet.. since a few weeks.
     
    LukeDawn likes this.
  11. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Absolutely.
     
    PraetorBlue likes this.
  12. LukeDawn

    LukeDawn

    Joined:
    Nov 10, 2016
    Posts:
    403
    Error appears on any element that uses a layer mask in the inspector, if you have layer 31 used.
    Exists in: 2022.2.14 onwards
    Does not exist in: 2022.1.24 or in 2023.1.0b15
    Issue ID: 1289876
     
    Last edited: May 6, 2023
  13. DrunkenMastah

    DrunkenMastah

    Joined:
    Sep 26, 2017
    Posts:
    51
    Fixed in 2022.2.21f1 .. they just haven't released it yet.