Well, you can't call the GenerateUnitFrames during combat, the GenerateUnitFrames is used to replace the "refreshUnitChange" to "_onattributechanged", here is a simple version
Lua Code:
local _Task = {}
grpHeader:SetScript("OnUpdate", function(self, elapsed)
if not InCombatLockdown() and #_Task > 0 then
for _, cnt in ipairs(_Task) do
GenerateUnitFrames(self, count)
end
wipe(_Task)
end
end)
function grpHeader:UpdateUnitCount(count)
tinsert(_Task, count)
end
If you don't create buttons based on the auto-generated unit buttons, the refreshUnitChange and _onattributechanged will do the same work, only the refreshUnitChange won't be fired when a unit is set to nil, so I replace it with a better one when out of combat.