Search Unity

What are the built-in Layers and Tags meant for?

Discussion in 'Scripting' started by cdalexander, Nov 23, 2009.

  1. cdalexander

    cdalexander

    Joined:
    Nov 9, 2009
    Posts:
    73
    I searched around for the answer to this but without success. I know that some tags/layers have a special meaning or function and some that perhaps don't.

    I know how to create tags and layers and how I can use them and heard that some of the built-in layers enable certain functionality (like the Ignore Raycast). But, does anyone know where I can find the documentation or something that explains what the built-in layers and tags are for?

    On a related note (but probably require its own topic) -- is there any hope or plans for the documentation on the site to be upgraded?

    There are way to many vague definitions that have little to no examples. Although the tutorials are fantastic and certainly help the new comer in many ways; fixing the online documentation would kick off a movement in Unity not seen since PHP came to the web (which has the best documentation format IMHO!!)


    Thanks mucho!
     
    torsknod and DougRichardson like this.
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    Tags are used to identify objects from within scripts. You can see it as an alternative to the name of a GameObject:
    http://unity3d.com/support/documentation/Components/Tags.html

    Layers are used to allow groups of objects to be enabled/disabled for Cameras, Lights or physics (usually for performance reasons):
    http://unity3d.com/support/documentation/Components/Layers.html
     
  3. cdalexander

    cdalexander

    Joined:
    Nov 9, 2009
    Posts:
    73
    Right, I understand what they are used for in general.

    My question is related to the built-in layers and tags -- Is there any functionality attached to each one.

    One example is the Ignore Raycast, which I assume that objects in this layer will be ignored by raycast colliders. Do the others provide some additional feature like this or are they "for examples" only?
     
    torsknod and chaoliu2333 like this.
  4. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    Ah, sorry. I should learn to read.

    Tags don't have any functionality attached unless you program it, the default ones just exist for convenience.

    As for the layers, I assume "Ignore Raycast" is not part of the "kDefaultRaycastLayers" mask in Physics.Raycast. I have never encountered any purpose for Water and TransparentFX, perhaps they are also there for convenience. As you said, it's quite unclear in the manual.
     
  5. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    I believe the other layers are directly related to the special effects used in the demonstration projects and tutorials Unity provides. Aside from Ignore Raycast, which the documentation mentions is left out of Raycast layers by default, those layers are just meant to be used at your convenience.

    In the end, you could just make your own if you don't like how they're named, so it's no big deal.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you put objects on the TransparentFX layer, then things like lens flares show through them. The water objects from standard assets and pro assets use the Water layer...I don't think it does anything special per se, so I assume it's included by default since there's no way to automatically add a layer when adding a prefab to the scene.

    --Eric
     
  7. Gaiyamato

    Gaiyamato

    Joined:
    Nov 19, 2009
    Posts:
    95
    This is useful to know... and needs to be in the docs and manual.
     
  8. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I agree, if built-in layers have their special purposes the docs should mention them somewhere, otherwise how would we take advantage of such functionality, most of us don't have a source code license.

    In a related note, could some of these layers be used by the editor? is it safe for me to use say built-in layer 7 for my editor scripts?
     
  9. Ferb

    Ferb

    Joined:
    Jan 4, 2014
    Posts:
    25
    According to the manual page on tags, there are 7 built in tags:
    • “Untagged”
    • “Respawn”
    • “Finish”
    • “EditorOnly”
    • “MainCamera”
    • “Player”
    • and “GameController”.

    But no, I haven't found any documentation about what each of them do, though I have over time picked up knowledge about a few of them.

    Things are generally 'Untagged' by default, though I don't know if setting the tag to that would have the same effect as setting it to an empty string. Whichever camera is tagged as 'MainCamera' is, I assume, the one you will get by referencing 'Camera.Main' - I don't know what will happen if you try to tag more than one, or no cameras, as 'MainCamera'. And 'EditorOnly' means a gameobject will be left out when you build the game - I like this one when building my levels, since I might have a gameobject just holding a script or something that will generate a visible effect in the game, but not in the editor. So to make it visible in the editor, I give it an 'EditorOnly' child with whatever visible objects I like, knowing that that gameobject and any resources it uses won't take up space in my compiled game. I'm afraid I don't know specifically what the other 4 built-in tags do.
     
    torsknod likes this.
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If there's more than one, then Camera.main returns the first one—whichever is "first" is undefined. If there are none, then Camera.main returns null.

    --Eric
     
    aklgupta likes this.
  11. Shine_Bolt

    Shine_Bolt

    Joined:
    Apr 13, 2018
    Posts:
    4