If you want your addon to work together with other addons which also modifies the tooltips,
you might need to be a little more sophisticated around how you modify your lines.
You will not always know which lines are yours. And clearing the entire tooltip will end up clearing more than you want too...
Here is the approach I ended up using:
Code:
local cachedUnit = nil
function OnTooltipSetUnit()
--Figure out if we are reading data from mouseover or target
local unit = "mouseover"
if (not UnitExists(unit)) then
unit = "target"
end
--Cache unit so that we can run it again later with the same unit
cachedUnit = unit
AppendCustomTooltipLines()
end
function AppendCustomTooltipLines()
--Add custom lines here with custom color
local r = 1
local g = 1
local b = 1
GameTooltip:AddLine("Custom text here...", r, g, b)
end
function UpdateTooltip()
if cachedUnit == nil then return end
--Makes sure custom tooltip lines are cleared
GameTooltip:SetUnit(cachedUnit)
end
GameTooltip:HookScript("OnTooltipSetUnit", OnTooltipSetUnit)
You may then call UpdateTooltip() wherever, when you know there is new data to apply.