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 How to get an object's Tag? (Not as a string but as the Tag class)

Discussion in 'Scripting' started by Fakkau, May 6, 2021.

  1. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    'gameObject.tag' will return the GameObject's tag as a string, but I'd like to know how to get an object's tag in the form of the actual Tag class. Does anyone know how to do this easily?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I am unfamiliar with this class. Can you direct me to the documentation?
     
  3. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    Hmmm... weird, I cannot find the documentation, yet I'm definitely able to create a variable of type Tag in C#. Making it a public variable creates a dropdown in the Inspector that lets you select a tag.
     
  4. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    Wait never mind, I had some plugin installed that created a custom Tag class that was basically just a string. My bad haha, thanks for the help anyway
     
    Kurt-Dekker likes this.