Skip to content

UI Avatar

Updated

Round profile picture with a status dot.

Type
ent-ui-avatar
Script class
UIAvatarEntity
Family
UI

A UI Avatar is a round profile picture: a player in a friends list, the speaker in a chat bubble, the host of a room. Its UI Avatar component (comp-ui-avatar) crops the picture in src to a circle and can draw a coloured status dot at its lower right, such as green for online. While the picture is missing or still loading, it shows the initials you give it, or a user icon.

An avatar sits nested in a panel or layout, often in a row beside a name label. With a Signal Emitter on its entity, a press sends UIAvatar::press {}; with a Link component, a press opens a web page instead.

Use a UI Avatar for people. For any other picture, use a UI Image, which takes any size and shape.

The props that matter most:

  • src: the picture, cropped to a circle.
  • initials: the fallback text while there is no picture, with initialsBackgroundColor and initialsColor.
  • size: the diameter in layout pixels (px), 40 by default.
  • statusColor: the status dot’s colour; absent, there is no dot.
  • borderColor and borderWidth: a ring around the picture, drawn only when borderColor is set.
  1. Add a UI Avatar under a UI Panel or UI Layout, for example in a row with a UI Label for the name. See Scenes and hierarchy.
  2. Set src and initials, and a size.
  3. Set statusColor if the avatar shows presence.
  4. Add a Signal Emitter if pressing it should do something.

Goal: show a friend’s picture and initials, and colour the status dot as they come and go.

FriendCard.jx
#pragma lifecycle(startup)
// Scene: a UI Avatar named 'Friend' beside a UI Label named 'Friend Name'.
// Other scripts emit 'friend:status' with 'online', 'away' or 'offline'.
const COLORS = { online: '#22c55e', away: '#f59e0b' };
function startup() {
const avatar = findEntity('Friend').getComponent(UIAvatarComponent);
const name = findEntity('Friend Name').getComponent(UILabelComponent);
avatar.setProps({ src: '/assets/people/maya.jpg', initials: 'MR', size: 48 });
name.setProps({ text: 'Maya Ruiz' });
on('friend:status', (status) => {
avatar.setProps({ statusColor: COLORS[status] });
name.setProps({ color: status === 'offline' ? '#64748b' : '#ffffff' });
});
}

How it works:

  • initials: 'MR' shows while the picture loads, or if it never does.
  • COLORS[status] is undefined for 'offline', which removes the dot; the name greys out too.

Goal: pressing the avatar shows a profile panel beside it.

ProfilePopup.jx
#pragma lifecycle(startup)
// Scene: a UI Avatar named 'Host' with a Signal Emitter on 'host:avatar',
// and a UI Panel named 'Host Profile', disabled at start.
let open = false;
function startup() {
const avatar = findEntity('Host').getComponent(UIAvatarComponent);
const profile = findEntity('Host Profile');
avatar.setProps({ borderColor: '#38bdf8', borderWidth: 2 });
on('host:avatar', (event) => {
if (event.eventType !== EventType.UIAvatar.Press) return;
open = !open;
profile.setEnabled(open);
});
}

How it works:

  • The Signal Emitter makes the avatar pressable; each press arrives as UIAvatar::press.
  • A ring with borderColor hints that the avatar can be pressed.
  • setEnabled shows and hides the profile panel with everything in it.

What a new UI Avatar is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
UI Avatar comp-ui-avatar Required One Round profile picture with a status dot.

You can also add 3 optional components, such as Attribution, Link, Signal Emitter.

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • UIAvatar::press

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My UI Avatar.

UIAvatarEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Avatar');
if (!(entity instanceof UIAvatarEntity)) return;
// Its UI Avatar component holds the settings listed under Props.
const component = entity.getComponent(UIAvatarComponent);
log(component.props);
}