Returns the name of a unit


See also Unit functions.

Signature:

name, realm = UnitName("unit")

Arguments:

  • unit - A unit to query (string, unitID)

Returns:

  • name - Name of the unit (string)
  • realm - Name of the unit's home realm if the unit is not from the player's realm; otherwise nil (string)

Examples:

-- Send a chat message to the player that's you are currently mousing over
-- This should be run as a macro (via keybind) so your mouse can be hovering
-- over a unit in the 3-D world, or a unit frame

local name = UnitName("mouseover")
SendChatMessage("Hey " .. name .. " I'm mousing over you!!!", "WHISPER", nil, name)

-- This can be run as a macro by putting it all on one line, and adding run
-- in front of it, like so:
--
-- /run local name = UnitName("mouseover"); SendChatMessage("Hey " .. name .. " I'm mousing over you!!!", "WHISPER", nil, name)