View Single Post
11-08-05, 06:37 PM   #1
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
UnitName() returning "Unknown Entity"

This is a strange bug that I'm not sure why is occuring. My set name function for my party mod uses UnitName("party1") for example to get the first party members name, and it works most of the time. Under certain conditions though, it returns Unknown Entity for usually all but one of the party members and I can't figure out why.

The events that I use to catch it are:
Code:
elseif ((event == "PARTY_MEMBERS_CHANGED") or (event == "PARTY_LEADER_CHANGED")) then
		Perl_Party_MembersUpdate();			-- How many members are in the group and show the correct frames and do UpdateOnce things
		Perl_Party_Update_Leader_Loot_Method();		-- Who is the group leader and who is the master looter
		return;

MembersUpdate just populates all the different bits of information accordingly, which shouldnt be the problem, but justin case, here's that function.

Code:
function Perl_Party_MembersUpdate()
	for partynum=1,4 do
		local partyid = "party"..partynum;
		local frame = getglobal("Perl_Party_MemberFrame"..partynum);
		if (UnitName(partyid) ~= nil) then
			frame:Show();
		else
			frame:Hide();
		end
	end
	Perl_Party_Update_PvP_Status();
	Perl_Party_Update_Level();
	Perl_Party_Update_Health();
	Perl_Party_Update_Dead_Status();
	Perl_Party_Update_Mana();
	Perl_Party_Update_Mana_Bar();
	Perl_Party_Update_Leader_Loot_Method();
	Perl_Party_Buff_UpdateAll();
	Perl_Party_Set_Name();
	Perl_Party_Set_Class_Icon();
	getglobal(this:GetName().."_NameFrame_PVPStatus"):Hide();	-- Set pvp status icon (need to remove the xml code eventually)
	HidePartyFrame();
end

And finally, here is the set name function that works perfectly after a /console reloadui

Code:
function Perl_Party_Set_Name()
	local partyid = "party"..this:GetID();
	local partyname = UnitName(partyid);
	-- Set name
	if (UnitName(partyid) ~= nil) then
		if (strlen(partyname) > 20) then
			partyname = strsub(partyname, 1, 19).."...";
		end
		getglobal(this:GetName().."_NameFrame_NameBarText"):SetText(partyname);
	end
end

To save some time looking at what WoWWiki says about this, I'll just put it here.
UnitName("player") (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.
Again, everything works flawlessly in raids or after a /console reloadui. It's just when you log in and get invited to a party, it will show Unknown Entity when "local partyname = UnitName(partyid);" is called for some reason. I read the wowwiki thing about this, but unfortunately it didn't really explain how to avoid it at all. Also, I thought i would be smart and make a loop so that the first time it gets unknown, it would call it again until a real name was given. This just crashes wow. Information such as pvp status does not return correctly, and neither is the class that these players are. Oddly enough, the tooltips for the unknown entity players work just fine. So I am totally confused.
  Reply With Quote