# tag

> The tag assigned to the GameObject.

## Definition

* **Type:** Property
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public string tag { get; set; }
```

### Remarks

A tag can be used to identify a GameObject. Tags must be declared in the [Tags and Layers manager](/engine/6000.7/manual/unity-editor/editor-settings-reference/comp-manager-group/class-tag-manager.md) before using them.

**Note:** Do not set a tag from [Awake()](/engine/6000.7/script-reference/unityengine/monobehaviour/awake.md) or [OnValidate()](/engine/6000.7/script-reference/unityengine/monobehaviour/onvalidate.md). The order in which `Awake` is called is not deterministic between components and a tag can be overwritten when its `Awake` is called. If you do this, Unity generates the warning `SendMessage cannot be called during Awake, CheckConsistency, or OnValidate`.

The example below sets the current GameObject's tag to "Player" and then implements [MonoBehaviour.OnTriggerEnter(Collider)](/engine/6000.7/script-reference/unityengine/monobehaviour/ontriggerenter.md) to check if the [Collider](/engine/6000.7/script-reference/unityengine/collider.md) on the other object involved in a collision with this object is tagged "Enemy".

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        //Set the tag of this GameObject to Player
        gameObject.tag = "Player";
    }

    private void OnTriggerEnter(Collider other)
    {
        //Check if the collider of the other GameObject involved in the collision is tagged "Enemy"
        if (other.tag == "Enemy")
        {
            Debug.Log("Triggered by Enemy");
        }
    }
}
```

Additional Resources: [GameObject.CompareTag](/engine/6000.7/script-reference/unityengine/gameobject/comparetag.md), [MonoBehaviour](/engine/6000.7/script-reference/unityengine/monobehaviour.md)
