Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:API UnitName
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Advanced
Special characters
Help
Heading
Level 2
Level 3
Level 4
Level 5
Format
Insert
Latin
Latin extended
IPA
Symbols
Greek
Greek extended
Cyrillic
Arabic
Arabic extended
Hebrew
Bangla
Tamil
Telugu
Sinhala
Devanagari
Gujarati
Thai
Lao
Khmer
Canadian Aboriginal
Runes
Á
á
À
à
Â
â
Ä
ä
Ã
ã
Ǎ
ǎ
Ā
ā
Ă
ă
Ą
ą
Å
å
Ć
ć
Ĉ
ĉ
Ç
ç
Č
č
Ċ
ċ
Đ
đ
Ď
ď
É
é
È
è
Ê
ê
Ë
ë
Ě
ě
Ē
ē
Ĕ
ĕ
Ė
ė
Ę
ę
Ĝ
ĝ
Ģ
ģ
Ğ
ğ
Ġ
ġ
Ĥ
ĥ
Ħ
ħ
Í
í
Ì
ì
Î
î
Ï
ï
Ĩ
ĩ
Ǐ
ǐ
Ī
ī
Ĭ
ĭ
İ
ı
Į
į
Ĵ
ĵ
Ķ
ķ
Ĺ
ĺ
Ļ
ļ
Ľ
ľ
Ł
ł
Ń
ń
Ñ
ñ
Ņ
ņ
Ň
ň
Ó
ó
Ò
ò
Ô
ô
Ö
ö
Õ
õ
Ǒ
ǒ
Ō
ō
Ŏ
ŏ
Ǫ
ǫ
Ő
ő
Ŕ
ŕ
Ŗ
ŗ
Ř
ř
Ś
ś
Ŝ
ŝ
Ş
ş
Š
š
Ș
ș
Ț
ț
Ť
ť
Ú
ú
Ù
ù
Û
û
Ü
ü
Ũ
ũ
Ů
ů
Ǔ
ǔ
Ū
ū
ǖ
ǘ
ǚ
ǜ
Ŭ
ŭ
Ų
ų
Ű
ű
Ŵ
ŵ
Ý
ý
Ŷ
ŷ
Ÿ
ÿ
Ȳ
ȳ
Ź
ź
Ž
ž
Ż
ż
Æ
æ
Ǣ
ǣ
Ø
ø
Œ
œ
ß
Ð
ð
Þ
þ
Ə
ə
Formatting
Links
Headings
Lists
Files
References
Discussion
Description
What you type
What you get
Italic
''Italic text''
Italic text
Bold
'''Bold text'''
Bold text
Bold & italic
'''''Bold & italic text'''''
Bold & italic text
{{wowapi}} __NOTOC__ <!-- Describe the purpose of the function, exhausting detail can be saved for a later section --> Returns the name and realm of the specified unit. <!-- List return values and arguments as well as function name, follow Blizzard usage convention for args --> name, realm = UnitName("unit") == Parameters == === Arguments === <!-- List each argument, together with its type --> :("unit") :;unit : String - The [[API TYPE UnitId|UnitId]] to query (e.g. "player", "party2", "pet", "target" etc.) === Returns === <!-- List each return value, together with its type --> :;name :: String - The name of the specified unit, "nil" if not applicable (e.g., if the specified unit is "target" but the player has no target selected). :;realm :: String - The realm the specified unit is from. For "player" returns nil, for any other character on your own realm returns an empty string. This is as of 1.12 == Example == <!-- If it helps, include an example here, though it's not required if the usage is self-explanatory --> <!-- begin code --> local playerName = UnitName("player"); ChatFrame1:AddMessage('Hi my name is: ' .. playerName); <!-- end code --> ====Result==== <!-- If it helps, include example results here, though they are not required. You're allowed to cheat liberally since WoW isn't a command line language. --> :Prints the player's name to the chat frame. e.g. <!-- begin code --> Hi my name is: Octon <!-- end code --> ==Details== <!-- Details not appropriate for the main description can go here. REMOVE the section if you're just going to restate the intro line! --> * UnitName("unit") (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. * The '''realm''' return will be nil even if the player is from a different realm, if it is out of visible range. * Realm name will not include server type * Note that this function always returns two values even though the latter may be nil. The difference is usually moot, but there are some cases where it matters, e.g. <span style="white-space: nowrap;"><tt>tinsert(myTable, UnitName("player"))</tt></span>, which would previously work, but will now cause errors. The fix is to put the expression in parenthesis: <span style="white-space: nowrap;" ><tt>tinsert(myTable, (UnitName("player")) )</tt></span>. * The default Blizzard UI defines [[API_GetUnitName|GetUnitName]](unit, showServerName) which only returns the unit name, but for characters from another server appends the server name (showServerName==true) or "(*)" (if showServerName==false). [[Category:World of Warcraft API]]
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Template:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Tocright
(
edit
)
Template:Wowapi
(
edit
)