Outline and silhouette
Updated
Two components draw a line around an entity. An Outline draws a coloured line around the whole entity, optionally animated: use it to highlight what the player can pick up, what the pointer is over, or what is selected. A Silhouette draws a line only around the parts of an entity that something else hides: use it to keep a player, a teammate or a key item visible through walls. Both show in the editor and in play, and look the same on desktop, mobile and in VR/AR headsets.
From a script you switch them on and off, restyle them and add them to entities at run time. This page shows how.
Before you start
Section titled “Before you start”- Entities and components. An Outline or a Silhouette is a component you add to an entity, read with
getComponent, change withsetPropsand switch withsetEnabled. See Components. - Signals. To react to the pointer or to selection, a script listens to the events a Selectable sends through a Signal Emitter. See Input and interaction and Scripting.
| Component | Type | What it does |
|---|---|---|
| Outline | comp-outline | Draws a colored, optionally animated outline around the entity. |
| Silhouette | comp-silhouette | Draws a colored outline around the parts of the entity hidden behind other objects. |
Outline
Section titled “Outline”OutlineComponent adds a line around its entity on meshes, models, primitives, groups, splats, fire, water, terrain, media and UI entities.
The rule is simple: the outline shows while the component is enabled. setEnabled(false) removes it and setEnabled(true) brings it back. Selecting an entity does not outline it on its own; you wire that yourself (see Examples).
An Outline wraps its entity and every child entity, so an Outline on a Group outlines everything in it as one shape. A child that has its own enabled Outline is drawn in its own style instead; a child whose Outline is disabled is drawn in the parent’s style.
Car (Outline) ← outlined ├── Wheel (Outline, red) ← in its own red └── Decal ← in the Car's styleOutline props
Section titled “Outline props”| Prop | Type | Default | Description |
|---|---|---|---|
color |
string | number |
'#38bdf8' |
Line colour. Ignored by the rainbow animation. |
thickness |
number |
4 |
Line width, 0 to 128: CSS pixels on desktop, each eye’s pixels in a headset. |
animation |
'none' | 'fade' | 'blink' | 'stripes' | 'rainbow' | 'sweep' |
'none' |
How the line animates (below). |
speed |
number |
1 |
Seconds per animation cycle, 0.001 to 3600. Lower is faster. |
| Animation | What you see |
|---|---|
none |
A steady line. |
fade |
Eases between faint and full. |
blink |
On for half of each cycle, off for the other half. |
stripes |
Diagonal stripes scroll along the line. |
rainbow |
Flows through the hues, ignoring color. |
sweep |
A bright band travels across the object. |
How an outline is drawn
Section titled “How an outline is drawn”- Always fully visible. The line draws without a depth test, so the floor under the object or a wall in front never cuts it.
- Closed on hard edges. On ordinary, skinned, morphed and instanced meshes the line is a hull pushed out along smoothed normals, so a cube keeps a closed line.
- Borders for flat and special content. Images, PDF pages, video, 2D text and SVG drawings get one border along their bounds. Splats, fire and water get a border around their bounds. UI panels get a border that follows their layout.
- Overlaps blend once. A stencil mask keeps the object’s own pixels clear, so overlapping faces do not darken the line.
Silhouette
Section titled “Silhouette”SilhouetteComponent goes on the same entities as an Outline. It outlines only what hides its entity: behind a wall or another object, the line shows where the entity is; fully in view, nothing shows. It is meant to stay on all the time. Like an Outline, it covers its child entities, and a child with its own enabled Silhouette is drawn in that one’s style.
Amelia walks back and forth behind a wall; her Silhouette, in the runtime Outlines & Silhouettes demo's cyan, shows her outline wherever the wall hides her.
Watch the cyan outline follow Amelia while she is behind the wall. Drag to orbit the camera, scroll to zoom.
Silhouette props
Section titled “Silhouette props”| Prop | Type | Default | Description |
|---|---|---|---|
color |
string | number |
'#f59e0b' |
Line colour. |
thickness |
number |
4 |
Line width, 0 to 128: CSS pixels on desktop, each eye’s pixels in a headset. |
threshold |
number |
0.05 |
Metres, 0 to 10000. Only what is nearer than the entity by at least this much hides it, so a floor or wall the entity touches draws no line. |
- One Silhouette entity in front of another hides the other’s line where they overlap.
- A Silhouette needs a stencil buffer. The runtime’s canvas and the post-processing buffer always have one.
Both on one entity
Section titled “Both on one entity”An entity can have an Outline and a Silhouette at the same time. Each draws on its own. Where both would draw over a hidden part, the Silhouette shows. An outlined object in front never hides a Silhouette behind it.
Scripting members
Section titled “Scripting members”Both components use the members every component has:
| Member | What it does |
|---|---|
set |
Change one or more props, for example set. Props you leave out keep their values. |
set |
Show (true) or hide (false) the line without removing the component. |
enabled |
Whether the component is enabled. |
props |
The current props. Read them; change them with setProps. |
Add one at run time with entity.addComponent(new OutlineComponent({ ... })) or new SilhouetteComponent({ ... }), and remove it with entity.removeComponent('comp-outline').
Both components can also be replicated in a multiplayer scene as network traits, NetworkTraitType.Outline and NetworkTraitType.Silhouette. See Multiplayer.
Examples
Section titled “Examples”1. Highlight what the pointer is over
Section titled “1. Highlight what the pointer is over”The simplest use: show an outline while the pointer hovers an object. The object has a Selectable (so the pointer can find it), an Outline saved disabled, and a Signal Emitter with the signal chest/pointer that lets Selectable::hover and Selectable::leave through. The Behavior sits on the same entity.
#pragma lifecycle(startup)
function startup() { const outline = self.parent.getComponent(OutlineComponent); outline.setEnabled(false);
on('chest/pointer', (event) => { if (event.eventType === EventType.Selectable.Hover) outline.setEnabled(true); if (event.eventType === EventType.Selectable.Leave) outline.setEnabled(false); });}A chest shows an outline while the pointer is over it: a Selectable forwarding hover and leave through a Signal Emitter, and a Behavior script switching an Outline on and off.
Move the pointer over the chest and away again. Drag to orbit the camera, scroll to zoom.
self.parent.getComponent(OutlineComponent)finds the Outline on the script’s own entity.outline.setEnabled(false)makes sure the line starts hidden even if the Outline was saved enabled.on('chest/pointer', …)receives every event the Signal Emitter forwards. Each event carries aneventType, which the script compares with theEventType.Selectableconstants instead of typing strings.- Switching the component is all it takes: the outline appears and disappears with no other setup.
2. Outline the selected object, and restyle it while it is held
Section titled “2. Outline the selected object, and restyle it while it is held”This script outlines an object while it is selected, uses a calm style by default and a bright animated style while the player grabs it. The object has a Selectable, a Grabbable, an Outline and one Signal Emitter with the signal crate/state and an empty filter, so every event reaches the script.
#pragma lifecycle(startup)
const IDLE = { color: '#38bdf8', thickness: 4, animation: 'none' };const HELD = { color: '#facc15', thickness: 6, animation: 'sweep', speed: 0.6 };
function startup() { const outline = self.parent.getComponent(OutlineComponent); outline.setProps(IDLE); outline.setEnabled(false);
on('crate/state', (event) => { switch (event.eventType) { case EventType.Selectable.Select: outline.setEnabled(true); break; case EventType.Selectable.Deselect: outline.setEnabled(false); break; case EventType.Grabbable.Start: outline.setProps(HELD); break; case EventType.Grabbable.End: outline.setProps(IDLE); break; } });}A crate is outlined in a calm style while it is selected, and in a bright sweeping style while it is grabbed, from one listener on all its events.
Click the crate to outline it, drag it to see the held style, and click empty space to clear it. Drag elsewhere to orbit the camera.
- The two styles are plain objects kept in constants, so the script never builds a new object per event and both looks are easy to tune in one place.
SelectandDeselectswitch the line;Grabbable.StartandGrabbable.Endonly change its style. Style changes apply only when props change, so this costs nothing between events.- The same result is possible without code, with an Enable on Signal whose
targetFilteris['Outline']and whoseactionis'toggle'. Use a script when you also want to restyle or count, as here.
3. See teammates through walls, and mark the quest item
Section titled “3. See teammates through walls, and mark the quest item”A realistic setup for a game: every teammate gets a Silhouette at startup, and the current quest item gets a blinking Outline that turns into a slow rainbow once the player is near it. A Behavior on any entity of the scene runs it.
#pragma lifecycle(startup, update)
const TEAMMATES = ['Ally 1', 'Ally 2', 'Ally 3'];const NEAR = 3; // metres
let item;let itemOutline;let near = false;const itemPosition = new THREE.Vector3();const eye = new THREE.Vector3();
function startup() { for (const name of TEAMMATES) { const ally = findEntity(name); if (!ally) continue; if (!ally.getComponent(SilhouetteComponent)) { ally.addComponent(new SilhouetteComponent({ color: '#22d3ee', thickness: 3 })); } }
item = findEntity('Quest Item'); if (!item.getComponent(OutlineComponent)) item.addComponent(new OutlineComponent({})); itemOutline = item.getComponent(OutlineComponent); itemOutline.setProps({ color: '#f97316', animation: 'blink', speed: 0.8 }); itemOutline.setEnabled(true);
on('quest/item-taken', () => itemOutline.setEnabled(false));}
function update() { if (!camera || !itemOutline.enabled) return; camera.getWorldPosition(eye); item.getWorldPosition(itemPosition); const isNear = eye.distanceTo(itemPosition) < NEAR; if (isNear === near) return; near = isNear; itemOutline.setProps(near ? { animation: 'rainbow', speed: 2 } : { animation: 'blink', speed: 0.8 });}Teammates behind a wall get a Silhouette at startup, so they show through it; the quest item gets a blinking Outline that turns into a rainbow when the camera is within 3 m.
See the three teammates through the wall and the blinking quest item. Scroll in close to the item to turn its outline into a rainbow. Drag to orbit the camera.
- Silhouettes once, at startup. Teammates are looked up by name once; each that has no Silhouette yet gets one. The line then shows only while a wall or another object hides them, so it can stay on for the whole session.
- Reuse or add. The quest item may already have an Outline from the editor. The script adds one only when it is missing, then reads the attached component with
getComponent. (addComponentreturns the entity, not the component, so that it can be chained.) - Change props only on change.
updatemeasures the distance every frame, but callssetPropsonly when the player crosses theNEARline. CallingsetPropsevery frame with the same values would be wasted work. - Vectors made once.
eyeanditemPositionare created at the top level and refilled each frame, so the script allocates nothing per frame. camerais the camera the player sees through; it isundefineduntil rendering starts, which the first line ofupdateguards against.- Another script raises
emit('quest/item-taken')when the item is collected, and the outline goes away.
4. Cycle a highlight through a list with the keyboard
Section titled “4. Cycle a highlight through a list with the keyboard”For menus in the world or tutorials, a script can move one highlight across several objects. Press Tab to outline the next one.
#pragma lifecycle(startup, update)
const NAMES = ['Lever A', 'Lever B', 'Lever C'];let outlines = [];let current = 0;
function startup() { outlines = NAMES.map((name) => { const entity = findEntity(name); entity.addComponent(new OutlineComponent({ color: '#a3e635', animation: 'fade', speed: 1.2 })); const outline = entity.getComponent(OutlineComponent); outline.setEnabled(false); return outline; }); outlines[current].setEnabled(true);}
function update() { if (!Input.keyboard.isKeyReleased(Key.Tab)) return; outlines[current].setEnabled(false); current = (current + 1) % outlines.length; outlines[current].setEnabled(true); emit('tutorial/focus', { name: NAMES[current] });}A script adds a fading Outline to three levers and enables one at a time; each press of Tab moves the highlight to the next lever.
Click the scene, then press Tab to move the highlight to the next lever. Drag to orbit the camera, scroll to zoom.
- Each lever gets its own Outline at startup, saved in an array so
updatenever searches the scene. Input.keyboard.isKeyReleased(Key.Tab)is true once per key press, so one press moves the highlight one step.- Only two components change per press: the old one is disabled and the new one enabled.
emittells other scripts (a hint panel, a sound) which lever is in focus.
Performance
Section titled “Performance”- No screen pass. Each outlined mesh is an ordinary draw, so outlines work per eye in XR and on mobile.
- Two draws per mesh, per eye. Each outlined or silhouetted mesh costs a stencil mask and the line. An Outline on a Group of 50 meshes costs 100 draws per eye. Outline the part that matters rather than a whole level.
- Free when unused. Nothing is allocated while nothing changes, and a scene with no Outline or Silhouette pays nothing.
- Hidden in reflections. Outlines and Silhouettes do not show in Reflector material reflections.
Common mistakes
Section titled “Common mistakes”- Forgetting the Signal Emitter. Without a Signal Emitter on the entity, Selectable and Grabbable events go nowhere and your
on(...)callback never runs. - Using a Silhouette as a highlight. A Silhouette shows only the hidden parts, so on an object in plain view it draws nothing. Use an Outline to highlight.
- Calling
setPropsevery frame. Change the style when something changes, not in everyupdate. - Outlining cached meshes. A mesh drawn by a Cache Mesh batch shows no Outline or Silhouette. See LOD and caching.
- Adding a second Outline. An entity holds one Outline.
addComponenton an entity that already has one replaces it, and the style saved in the editor is lost. Read the existing one withgetComponentand change it withsetPropsinstead.