UI Avatar
Updated
Round profile picture with a status dot.
- Type
ent-ui-avatar- Script class
UIAvatarEntity- Family
- UI
Overview
Section titled “Overview”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, withinitialsBackgroundColorandinitialsColor.size: the diameter in layout pixels (px), 40 by default.statusColor: the status dot’s colour; absent, there is no dot.borderColorandborderWidth: a ring around the picture, drawn only whenborderColoris set.
Set it up
Section titled “Set it up”- 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.
- Set
srcandinitials, and asize. - Set
statusColorif the avatar shows presence. - Add a Signal Emitter if pressing it should do something.
Examples
Section titled “Examples”A friend’s card with presence
Section titled “A friend’s card with presence”Goal: show a friend’s picture and initials, and colour the status dot as they come and go.
#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]isundefinedfor'offline', which removes the dot; the name greys out too.
Open a profile when pressed
Section titled “Open a profile when pressed”Goal: pressing the avatar shows a profile panel beside it.
#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
borderColorhints that the avatar can be pressed. setEnabledshows and hides the profile panel with everything in it.
Components
Section titled “Components”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- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| UI Avatar | comp- |
Required | One | Round profile picture with a status dot. |
You can also add 3 optional components, such as Attribution, Link, Signal Emitter.
Events
Section titled “Events”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.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
A profile card built from a UI Avatar with initials and a status dot, a UI Spacer that pushes the level badge right, and UI Dividers between the stats. Pressing the avatar cycles the status.
Press the avatar to cycle Online, Away and Busy: the status dot and the label change together. Drag outside the panel to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”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.
#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);}