WoW API: UnitName

WoW API < UnitName


Returns the name of the specified unit.

name = UnitName("unit")


Parameters

Arguments

("unit")
unit
String - The UnitId to query (e.g. "player", "party2", "pet", "target" etc.)

Returns

name
String - The name of the specified unit.


Example

local playerName = UnitName("player");
ChatFrame1:AddMessage('Hi my name is: ' .. playerName);

Result

Prints the player's name to the chat frame. e.g.
Hi my name is: Octon


Details

UnitName("player") (or any other unit) will return "Unknown Entity" (Actually the value of the UNKNOWNOBJECT global) if called before the unit in question has been fully loaded into the world.
In the upcoming patch 1.12, it seems that UnitName() returns two values: unit-name and server-name. The second value is only returned when used on a player from another server in a (cross-server) battleground.