Reply
Thread Tools Display Modes
Unread 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.
Global is offline   Reply With Quote
Unread 11-08-05, 07:12 PM   #2
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
your definatly running that after your in the group right? and not just on invite
noraj is offline   Reply With Quote
Unread 11-08-05, 07:27 PM   #3
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
pretty sure. I've looked at the default wow ui and they use the same events. I also had PARTY_MEMBER_ENABLE and PARTY_MEMBER_DISABLE in the elseif but it made no difference. also, the reason its weird is because its still reporting usually one of the members names correctly if theres 3 other party members. also, if i log into the game and do a /console reloadui, then get the invite, it works perfectly. which just adds to the wtf factor of this problem.
Global is offline   Reply With Quote
Unread 11-08-05, 07:35 PM   #4
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
why dont you throw in a getnumpartymembers() thing just in case?

that would catch it I think

I assumed you were but sometimes we overlook the most obvious

[edit] change
for partynum=1,4 do

to
partytotal = GetNumPartyMembers()
if (partytotal > 0 ) then
for partynum = 1 , partytotal do

...


and that *might fix it*

Last edited by noraj : 11-08-05 at 07:39 PM.
noraj is offline   Reply With Quote
Unread 11-08-05, 07:47 PM   #5
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
i'll try, but it's correctly displaying the number of people in the group. all the frames that should appear are there. it's just that i get the unknown entity value instead of a name. the for loop literally just displays or hides the party frames, never had any issues with it. kind of along these lines, in my hopeless attempt to fix the issue, i made this set name function:

Code:
--function Perl_Party_Set_Name()	--Failed attempt at the Unknown Entity fix
--	for partynum=1,4 do
--		local partyid = "party"..partynum;
--		local partyname = UnitName(partyid);
--		-- Set name
--		if (UnitName(partyid) ~= nil) then
--			if (strlen(partyname) > 20) then
--				partyname = strsub(partyname, 1, 19).."...";
--			end
--			getglobal("Perl_Party_MemberFrame"..partynum.."_NameFrame_NameBarText"):SetText(partyname);
--		else
--			-- do nothing since this should be taken care of by Perl_Party_MembersUpdate
--		end
--	end
--end
so even if the event or getid was malfunctioning, this would have fixed it, but the return value of party1 and such just isn't working without the reloadui.
Global is offline   Reply With Quote
Unread 11-09-05, 12:13 AM   #6
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
Just a quick "update" if you will. After doing some xml tweaking I did a few /console reloadui's and joined a group a few minutes later. Apparently the reloadui only works after you join a group since this screenshot is what happened after the initial reloadui and before a reloadui after joining the group (wow that sounds complicated).

click here for the pic

so yea, still totally lost as to why this is happening.
Global is offline   Reply With Quote
Unread 11-09-05, 02:42 AM   #7
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
rofl yeah thats weird...it might be that your in Orgrimarr though and its just lag

I dunno I always assume the easiest answer...its just a stab in the dark..
noraj is offline   Reply With Quote
Unread 11-09-05, 02:45 AM   #8
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
hah, i wish. unfortunately it happens anywhere.
Global is offline   Reply With Quote
Unread 11-09-05, 10:10 AM   #9
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
does the unkown unit resolve itself shortly after or does it stay an unknown entity?
noraj is offline   Reply With Quote
Unread 11-09-05, 02:13 PM   #10
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
if someone new gets invited to the group, it resolves itself. if you kick someone and reinvite it fixes the problem. zoning fixes the issue (i think) since that's basically a console reloadui.
Global is offline   Reply With Quote
Unread 11-09-05, 02:38 PM   #11
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
maybe toss in a

if(UnitName("PartyN") ~= "Unknown Entity") then
--Update your player frame names
else
while UnitName("PartyN") == "Unknown Entity" do end
--Update your player frame name
end

although thats going to lock up your system while it tries to get the actuall name(and if someone is actually named Unknown Entity theyre screwed

prolly a better way to accomplish it in the on update function rather than locking up your system

It might even crash wow

test it by doing a /script DEFAULT_CHAT_FRAME:AddMessage(UnitName("PartyN") for one of the party members thats displayed as Unknown Entity

[edit] in all honesty your prolly alot more proficient at LUA than me.
noraj is offline   Reply With Quote
Unread 11-09-05, 02:58 PM   #12
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
heh, i've tried that already too. of course i made it into a loop to ensure that it got the name. too bad it just ended up hardlocking wow. and when you have it print to the chat window it also just keeps spamming unknown ent, so something else is definately not triggering correctly.
Global is offline   Reply With Quote
Unread 11-09-05, 03:25 PM   #13
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
did you try to do a
/script DEFAULT_CHAT_FRAME:AddMessage(UnitName("PartyN")
for one of the party members thats displayed as Unknown Entity to see if it returns a name
if it does try the code changes below...dunno might help...not so much a solution as a work around(if it works)

Code:
function Perl_Party_Set_Name()	--Failed attempt at the Unknown Entity fix
--	       WeirdBehaviorFlag = nil -- this is the flag if we're getting Unknown Entity
                for partynum=1,4 do
--		local partyid = "party"..partynum;
--		local partyname = UnitName(partyid);
--		-- Set name
--		if (UnitName(partyid) ~= nil) then
                        if( partyname == "Unknown Entity") and (not WeirdBehaviorFlag) then WeirdBehaviorFlag = 1 end 
--			if (strlen(partyname) > 20) then
--				partyname = strsub(partyname, 1, 19).."...";
--			end
--			getglobal("Perl_Party_MemberFrame"..partynum.."_NameFrame_NameBarText"):SetText(partyname);
--		else
--			-- do nothing since this should be taken care of by Perl_Party_MembersUpdate
--		end
--	end
--end
I bolded my suggested changes
then in your OnUpdate Handler toss in a
if(WeirdBehaviorFlag ) then function Perl_Party_Set_Name() end -- check the party again if there is an "Unknown Entity"

and see if that gets it to load
noraj is offline   Reply With Quote
Unread 11-09-05, 03:56 PM   #14
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
the problem with using the global flag is that theres no documentation on when it is set and reset. i'll try it out though if my current tweak doesn't work.

i changed my members update function to:

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();
			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();
		else
			frame:Hide();
		end
	end

	getglobal(this:GetName().."_NameFrame_PVPStatus"):Hide();	-- Set pvp status icon (need to remove the xml code eventually)
	HidePartyFrame();
end
So far i've relogged twice and been invited and it's loaded the names and everything perfectly. If this does end up working, then calling unitname on a party member that doesn't exist, or something, has some pretty weird side effects on future calls, or something...heh. I'm a total noob when it comes to this.GetID so it's probably something to do with that and how bliz orders the party members initially, but it's just a guess.

edit: i guess it didn't keep working for very long, oh well.

Last edited by Global : 11-09-05 at 04:01 PM.
Global is offline   Reply With Quote
Unread 11-09-05, 04:52 PM   #15
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
did you get a chance to try my code tweak

Basically it should unset at the start of that function and be set only if a Unknown gets returned)

I have a feeling its lag related as I seem to remember getting unit unknown(sometimes for a few minutes even) with the default UI

but it really shouldnt be happening ALL the time
noraj is offline   Reply With Quote
Unread 11-09-05, 05:53 PM   #16
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
my hat goes off to you sir. in the tests i've been running it seems to be working just fine. granted now i have to hit an if statement on every event, but i'm saving enough cpu cycles elsewhere over the default bliz ui to not care. i'll continue to test this fix and get back to you can't believe it's finally working right. thanks a ton!
Global is offline   Reply With Quote
Unread 11-09-05, 06:08 PM   #17
noraj
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 102
lol I figured that would fix it...its not the prettiest solution but it works
noraj is offline   Reply With Quote
Unread 11-09-05, 06:23 PM   #18
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
honestly, im totally shocked it worked since when i dropped a while loop in it just hardlocked wow. i really don't understand why this works and the loop didn't.
Global is offline   Reply With Quote
Unread 11-09-05, 06:58 PM   #19
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 393
I believe the solution to your problem is to register for the UNIT_NAME_UPDATE event. This event fires when a unit's name changes with arg1 being set to the unit whose name has been updated. When you join a party, I don't believe that the party member's names are guaranteed to be available until this event fires for each one because the client is still retrieving the information in order to make it available to the UI system.

On a related note, I believe the same is true of party member's levels and the UNIT_LEVEL event.

Last edited by Esamynn : 11-09-05 at 07:06 PM. Reason: more information
Esamynn is offline   Reply With Quote
Unread 11-09-05, 07:05 PM   #20
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
i'll definately take a look into this, thanks for the advice
Global is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » UnitName() returning "Unknown Entity"

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off