UserAvatar
A UserAvatar is a picture of a user or a character, in a circle, a rounded square, a hexagon or the shape of a mask texture. Without a picture it shows the initials of the name. The name Avatar is not used, because UnityEngine.Avatar has it.
![]()
![]()
How to add an avatar:
<tb:UserAvatar display-name="Ada Lovelace" />
<tb:UserAvatar name="player" display-name="Grace Hopper" size="48">
<tb:Badge dot="true" corner="true" tone="Success" />
</tb:UserAvatar>
var avatar = root.Q<UserAvatar>("player");
avatar.Image = Background.FromTexture2D(portrait); // or FromSprite
How to cut the picture to a hexagon:
<tb:UserAvatar display-name="Ana Ruiz" shape="Hexagon" />
| Member | Description |
|---|---|
DisplayName (display-name) |
The name. Its initials show when there is no image, and it is the tooltip. |
Image (image) |
The picture: a texture, a sprite, a render texture or a vector image. It fills the avatar and hides the initials. |
Size (size) |
The width and height in pixels. The initials take 40% of it as their font size. 0 (the default) uses the USS size, 32 px. |
Shape (shape) |
The cut of the picture: Circle (default), RoundedSquare, Hexagon or Texture. Circle and RoundedSquare clip the picture with the border radius of the image, so the ring of an AvatarGroup shows. Hexagon and Texture cut it with a MaskImage, so their edges are smooth, and they show no ring. |
MaskTexture (mask-texture) |
The mask when Shape is Texture: where its alpha is opaque, the picture shows. |
Square (square) |
The same as Shape RoundedSquare. When both are set, the one set last wins. |
UserAvatar.InitialsOf(name) |
The initials that the control shows: the first letter of the first word and of the last word, in upper case. "?" for an empty name. |
- Children of the avatar show on top of the picture. The picture itself is an inner element, so a corner badge is not clipped.
- The background of the initials is the accent color of the theme.
Tips:
- In UXML, set
imageto a texture or a sprite of the project with the UI Builder, or useimage="project://database/Assets/Portraits/Ada.png". - For a row of users, set the same
sizeon each avatar and give the rowflex-direction: row. - For a different color for each user, set
style.backgroundColoronavatar.Q(className: UserAvatar.IMAGE_CLASS).
In the examples



Styling
| Class | Element |
|---|---|
tb-avatar |
The control: 32 px wide and high. Size sets an inline width, height and font size. |
tb-avatar__image |
The inner element with the picture or the initials: a circle (border-radius: 50%) on --tb-color-accent. The picture is a MaskImage inside it, and the inner element clips it. |
tb-avatar__initials |
The bold initials, in --tb-color-accent-text. Hidden while the avatar has an image. |
tb-avatar--square |
An avatar with Shape RoundedSquare. The inner element takes --tb-radius-md. |
tb-avatar--hexagon, tb-avatar--texture |
An avatar with Shape Hexagon or Texture. |
tb-avatar--picture |
An avatar that has an image. |
tb-avatar__picture |
The MaskImage that shows the picture. It exists from the first image on. |
.tb-avatar__image {
background-color: var(--tb-color-surface-alt);
border-width: 2px;
border-color: var(--tb-color-accent);
}
.tb-avatar__initials { color: var(--tb-color-text); }
The UserAvatarDemo scene shows a guild roster of initials, a hero select with pictures, a friends list with an online dot on each avatar, and portraits in shapes, masks and frames.
SVG: Image is a Background. An SVG imported as a VectorImage works as well as a texture. See Pictures: PNG or SVG.