I tried to get the unit name of newly joined group members and found that it does not work as expected.
Here is the code I tested it with:
Lua Code:
EVENT_MANAGER:RegisterForEvent("nametest", EVENT_UNIT_CREATED, function(_, unitTag)
df("unit created: %s %s (%s)", tostring(unitTag), GetUnitDisplayName(unitTag), tostring(DoesUnitExist(unitTag)))
end)
When I make a new group, I get one EVENT_UNIT_CREATED for myself which is fine, but for some reason I get two events for whoever I invited. Besides that everything works fine in all three events.
Code:
unit created: group1 @sirinsidiator (true)
unit created: group2 @groupie1 (true)
unit created: group2 @groupie1 (true)
But when I invite another player, the first occurrence returns an empty name and only the second one works as expected.
Code:
unit created: group3 (true)
unit created: group3 @groupie2 (true)
DoesUnitExist does not help as it always returns true, so the only thing I can do is check for an empty string and ignore those events.