Skip to content

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.

  • Entities and components. An Outline or a Silhouette is a component you add to an entity, read with getComponent, change with setProps and switch with setEnabled. 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.
ComponentTypeWhat it does
Outlinecomp-outlineDraws a colored, optionally animated outline around the entity.
Silhouettecomp-silhouetteDraws a colored outline around the parts of the entity hidden behind other objects.

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 style
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.
  • 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.

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.

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.

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.

Both components use the members every component has:

Member What it does
setProps(patch) Change one or more props, for example setProps({ color: '#facc15', animation: 'sweep' }). Props you leave out keep their values.
setEnabled(on) 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.

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.

HoverOutline.jx
#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);
});
}
  • 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 an eventType, which the script compares with the EventType.Selectable constants 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.

SelectionOutline.jx
#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;
}
});
}
  • 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.
  • Select and Deselect switch the line; Grabbable.Start and Grabbable.End only 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 targetFilter is ['Outline'] and whose action is '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.

TeamVisibility.jx
#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 });
}
  • 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. (addComponent returns the entity, not the component, so that it can be chained.)
  • Change props only on change. update measures the distance every frame, but calls setProps only when the player crosses the NEAR line. Calling setProps every frame with the same values would be wasted work.
  • Vectors made once. eye and itemPosition are created at the top level and refilled each frame, so the script allocates nothing per frame.
  • camera is the camera the player sees through; it is undefined until rendering starts, which the first line of update guards 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.

CycleHighlight.jx
#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] });
}
  • Each lever gets its own Outline at startup, saved in an array so update never 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.
  • emit tells other scripts (a hint panel, a sound) which lever is in focus.
  • 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.
  • 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 setProps every frame. Change the style when something changes, not in every update.
  • 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. addComponent on an entity that already has one replaces it, and the style saved in the editor is lost. Read the existing one with getComponent and change it with setProps instead.