UIOBJECT GameTooltip

GameTooltip (inherits from ) formats a tooltip. There is one named _G["GameTooltip"], but others are created with or .
Custom tooltips made in Lua must inherit a virtual XML template:
* SharedTooltipTemplate - Includes base font strings and textures. 
* GameTooltipTemplate - Additionally includes a unit health bar. 
Alternatively, see for minimum requirements in XML.
__FORCETOC__
== Defined methods ==
== Details ==
* () clears and hides the tooltip, then sets a temporary "owner" independent of the frame's "parent".
** The second argument anchors the tooltip rather than ().
** Use ANCHOR_NONE for scanning tooltips (more details below).
* () resizes the tooltip and reapplies any anchor defined with SetOwner().
** Showing a tooltip without content causes it to hide and clear its owner.
** AppendText() and most Set methods (SetUnit, SetItemByID, etc.) trigger Show(); however, AddLine() and AddDoubleLine() do not.
* () clears the tooltip's owner.
** () is an alternative without clearing the owner (and anchor).
* () and similar methods add new lines as required, called _G["$parentTextLeft"..i] and _G["$parentTextRight"..i].
** Each new copies the same object as the previous line.
** However, the tooltip malfunctions without the first line present before loading (i.e. defined in XML).
== Scanning tooltips ==
AddOns commonly create a hidden tooltip with ANCHOR_NONE to query Set___() methods invisibly to the player. Scanning tooltips can impact performance, so it is best to cache results and consider other API whenever feasible.
<GameTooltip name="MyScanningTooltip" inherits="SharedTooltipTemplate">
	<Scripts>
		<OnLoad inherit="prepend">
			self:SetOwner(WorldFrame, "ANCHOR_NONE")
		</OnLoad>
	</Scripts>
</GameTooltip>
Each time scanning is desired, call ClearLines(), populate the tooltip, and then read the contents of the text fields.
MyScanningTooltip:ClearLines()
MyScanningTooltip:SetUnit("player")
print(MyScanningTooltipTextLeft2:GetText())
== Examples ==
Function to return a table containing all the lines in the tooltip
local function GetTooltipLines(tooltip)
 local textLines = {}
 local regions = {tooltip:GetRegions()}
 for _, r in ipairs(regions) do
 if r:IsObjectType("FontString") then
 table.insert(textLines, r:GetText())
 end
 end
 return textLines
end
Iterator for looping through all tooltip lines
local function EnumerateTooltipLines_helper(...)
 for i = 1, select("#", ...) do
 local region = select(i, ...)
 if region and region:GetObjectType() == "FontString" then
 local text = region:GetText() -- string or nil
 end
 end
end
function EnumerateTooltipLines(tooltip) -- good for script handlers that pass the tooltip as the first argument.
 EnumerateTooltipLines_helper(tooltip:GetRegions())
end
Macro to print each line:
 /run for i=1,GameTooltip:NumLines()do print(_G["GameTooltipTextLeft"..i]:GetText())end
Macro to print left and right lines:
 /run for i=1,select("#",GameTooltip:GetRegions())do local region=select(i,GameTooltip:GetRegions())if region and region:GetObjectType()=="FontString" and region:GetText()then print(region:GetText()) end end
Creating a scanning tooltip in Lua that has all features (status bar, textures, etc.):
CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
MyScanningTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" )
local function scanUnit(unit)
 MyScanningTooltip:ClearLines()
 MyScanningTooltip:SetUnit(unit)
 
 local i=1
 while _G["MyScanningTooltipTextLeft" .. i] do
 local text = _G["MyScanningTooltipTextLeft" .. i]:GetText()
 if text and text ~= "" then print(text) end
 i = i + 1
 end
end
scanUnit(player)