Avatar Nametags
Show a custom label above an avatar's nametag, to display a rank, a role, or a team.
The AvatarNametag component adds a small plate above an avatar's regular nametag, showing text that your scene chooses. Use it to show a rank, a role, a team, or anything else your scene tracks about a player, like "VIP", "Team Red", or "Club Owner".

This page covers how to add a plate, style it, and keep it in step as players come and go.
Add a plate to the player
The only required field is label, the text to show.
The plate uses the client's own nametag colors by default, so it matches the rest of the interface without any extra work.
Where the component works
AvatarNametag only does something on an entity that carries an avatar:
engine.PlayerEntity, the player running the scene.Another player's entity, found through their
PlayerIdentityDatacomponent.An NPC avatar, meaning any entity with an
AvatarShapecomponent.
On any other entity the component is ignored.
Change the colors
Three optional fields take a Color3:
labelColor: the text color. Defaults to the client's native nametag text color.backgroundColor: the plate's fill. Defaults to the client's native nametag background color.borderColor: the plate's outline. Defaults tobackgroundColor, so there is no visible border unless you set it.
To go back to the native colors for a field, write the component again without that field. Use createOrReplace rather than getMutable, because replacing the whole component is what clears the fields you left out:
Remove a plate
Use deleteFrom to take the plate away. The avatar's regular nametag is not affected:
Label behavior
A few details are worth knowing before you pick your label text:
Long labels are truncated with an ellipsis. Keep labels to a word or two.
An empty label (
'') draws the plate with no text in it.Spaces are kept, so a label made only of spaces widens a text-less plate. This is a way to size a plain colored plate.
To hide the word but keep its width, set
labelColorto the same value asbackgroundColor.
Tag players as they arrive
The simplest way to tag other players is to attach the component when they enter the scene, using the onEnterScene event. It hands you a fresh entity each time, so there is nothing to look up or cache:
See Get player data for more on tracking players as they enter and leave.
Tag every player in the scene
To show a plate over everyone at once, iterate over the entities that have a PlayerIdentityData component.
Collect the entities into an array before writing to them. Writing a component while still looping over engine.getEntitiesWith() can invalidate the query part-way through.
Comparing against the current value before writing avoids needless component updates on every pass.
Keep up with players joining and leaving
Player entity ids are not stable across disconnects. When a player leaves, their entity id is recycled and may be handed to the next player who joins, so a plate written to a stale entity ends up over the wrong avatar.
Two rules keep this correct:
Resolve the entity anew right before every write, rather than caching the entity.
Remove the component when a player leaves.
Re-running the tagging function on a timer catches players who join later and never holds on to stale entities. Once a second is frequent enough:
Plates in multiplayer scenes
Plates are local to each player's client. The plate is never sent to other players, each player's copy of the scene computes its own plates. If all players should see the same tags, the logic that assigns them must produce the same result on every client from data they all share. Sorting players by wallet address, as in the example above, is one way to do that. Otherwise, your scene needs to sync the assignments itself, see Serverless multiplayer.
Interaction with hidden nametags
An AvatarModifierArea with the AMT_HIDE_NAMETAGS modifier hides these plates along with the regular nametags. The same applies to AMT_HIDE_AVATARS, which hides the whole avatar.
If you want an avatar to show only your plate and no name underneath it, set the AvatarShape component's name to an empty string. See NPC Avatars.
Related pages
Avatar Modifier Areas: hide avatars and nametags inside a region of the scene.
Move the Player and Avatar Animations: control the player's avatar.
NPC Avatars: show avatars that aren't players.
Get player data: read data about the player and everyone else in the scene.
Color types: how to build
Color3values.
Last updated