Open Ghostopheles opened 1 month ago
Through the use of C_TooltipInfo.GetHyperlink
, I can confirm that the issue is indeed tied to the cache state of the specified creature. Using the below example code will handle uncached creatures and only call PlayerModel:SetCreature()
when the creature is fully loaded.
Due to the lack of a return from C_TooltipInfo.GetHyperlink
, I just assume the next TOOLTIP_DATA_UPDATE
event is related to our info call, which could cause some issues in an active environment. Also made CREATURE_ID
a global variable so it's easier to play around with.
CREATURE_ID = 186739;
local model = CreateFrame("PlayerModel", nil, UIParent, "ModelWithControlsTemplate");
model:SetPoint("CENTER");
model:SetSize(500, 500);
model:SetScript("OnModelLoaded", function() print("OnModelLoaded") end);
local function SetCreature(id)
print("Setting creature");
model:SetCreature(id);
end
local function LoadAndSetCreature(id)
local guid = format("unit:Creature-0-0-0-0-%s-0", id);
local data = C_TooltipInfo.GetHyperlink(guid);
if not data then
print("Requesting creature load");
EventUtil.RegisterOnceFrameEventAndCallback("TOOLTIP_DATA_UPDATE", function() SetCreature(id) end);
else
print("Creature already cached");
SetCreature(id);
end
end
local b = CreateFrame("Button", nil, model, "UIPanelButtonTemplate");
b:SetSize(125, 30);
b:SetPoint("LEFT", model, "RIGHT");
b:SetText("Set Creature");
b:SetScript("OnClick", function() LoadAndSetCreature(CREATURE_ID) end);
If the creature specified in the
PlayerModel:SetCreature()
function call hasn't been previously loaded and cached, the first call to:SetCreature()
will do nothing.This issue does not occur if you directly use
:SetModel()
or:SetDisplayInfo()
, indicating that the request for the uncached creature info using it's ID is the cause of the issue, not the cache state of the model itself.My assumption is that the initial call receives no return from the internal function used to look up the model by creature ID. It then requests for that data to be loaded, but doesn't properly notify the
PlayerModel
frame when it's ready, resulting in the need to call:SetCreature()
a second time for it to load the model correctly.Last tested on 10.2.7.54601
Repro
PlayerModel
framePlayerModel:SetCreature
with the CreatureID of a creature you haven't seen in a whileExample
Expected Behavior of Example Code