UnitName

From Warcraft Wiki
Jump to navigation Jump to search
GitHub Octocat.png  Townlong-Yak Globe.png  Townlong-Yak BAD.png  Blizz.gif  ProfIcons engineering.png  Wowprogramming.png UnitName 11.0.5 (57212)4.4.1 (57564)1.15.5 (57638) + 1.0.0 / 1.13.2
GitHub Octocat.png  Townlong-Yak Globe.png  Townlong-Yak BAD.png  Blizz.gif  ProfIcons engineering.png  Wowprogramming.png UnitFullName 11.0.5 (57212)4.4.1 (57564)1.15.5 (57638) + 5.4.2 / 1.13.2
GitHub Octocat.png  Townlong-Yak Globe.png  Townlong-Yak BAD.png  Blizz.gif  ProfIcons engineering.png UnitNameUnmodified 11.0.5 (57212)4.4.1 (57564)1.15.5 (57638) + 9.0.2 / 2.5.1 / 1.14.0

Returns the name and realm of the unit.

name, realm = UnitName(unit)
            = UnitFullName(unit)
            = UnitNameUnmodified(unit)

Arguments

unit
string : UnitId - For example "player" or "target"

Returns

name
string? - The name of the unit. Returns nil if the unit doesn't exist, e.g. the player has no target selected.
realm
string? - The normalized realm the unit is from, e.g. "DarkmoonFaire". Returns nil if the unit is from the same realm.

Details

  • Will return globalstring UNKNOWNOBJECT "Unknown Entity" if called before the unit in question has been fully loaded into the world.
  • The unit name will change if the unit is under the effects of  [Lifegiving Seed] or a similar effect, but UnitNameUnmodified() is unaffected by this.

Example

  • Prints your character's name.
/dump UnitName("player") -- "Leeroy", nil
  • Prints the name and realm of your target (if different).
/dump UnitName("target") -- "Thegnome", "DarkmoonFaire"
  • UnitFullName() is equivalent with UnitName() except it will always return realm if used with the "player" UnitId.
/dump UnitFullName("player") -- "Leeroy", "MoonGuard"
/dump UnitFullName("target") -- "Leeroy", nil

GetUnitName

GetUnitName(unit [, showServerName]) can return the combined unit and realm name.

  • If showServerName is true and the queried unit is from a different server, then the return value will include the unit's name appended by a dash and the normalized realm name.
  • If showServerName is false, then FOREIGN_SERVER_LABEL " (*)" will be appended to units from coalesced realms. Units from the player's own realm or Connected Realms get no additional suffix.

Unit is from the same realm.

/dump GetUnitName("target", true)  -- "Nephertiri"
/dump GetUnitName("target", false) -- "Nephertiri"

Unit is from a different realm but the same Connected Realm (LE_REALM_RELATION_VIRTUAL).

/dump GetUnitName("target", true)  -- "Standron-EarthenRing"
/dump GetUnitName("target", false) -- "Standron"

Unit is from a different, non-connected realm (LE_REALM_RELATION_COALESCED).

/dump GetUnitName("target", true)  -- "Celturio-Quel'Thalas"
/dump GetUnitName("target", false) -- "Celturio (*)"

Patch changes

See also