UI Toolbox logoUI Toolbox
Support

WorldMarkerLayer

A WorldMarkerLayer shows a marker over each HudTarget of the scene: an icon, a label and the distance. A target off the screen stays at the edge, with an arrow toward it. Use it for quest markers, waypoints, enemy tags and lock-on brackets.

Markers over a 3D scene: Mira and a Raider with a bracket, a name and the distance, and the targets off the screen at the edges with arrowsMarkers over a 3D scene: Mira and a Raider with a bracket, a name and the distance, and the targets off the screen at the edges with arrows

Video tutorial: World-space HUD. All videos: Video tutorials. Demo scene: WorldHudDemo.unity.

How to add the layer in UXML:

<ui:VisualElement class="hud-root">
    <tb:WorldMarkerLayer />
    <!-- the other HUD controls -->
</ui:VisualElement>

The layer fills its parent and takes no pointer event. It shows every HudTarget whose ShowOn has Marker, with no code.

How to put brackets around the selected units:

<tb:WorldMarkerLayer
    target-mark="Brackets"
    show-label="false"
    show-distance="false" />
// Each unit has a disabled HudTarget; the selection turns it on
target.enabled = selected;

How to add a part to each marker:

The layer pools its markers, so MarkerShown fires each time a marker shows for a target, also for a marker that was used before. Add the part in MarkerShown and remove it in MarkerHidden:

var markers = root.Q<WorldMarkerLayer>();
markers.MarkerShown += (target, marker) =>
{
    // The body exists in the built-in marker; a marker-template may not
    // have it
    var body = marker.Q(className: WorldMarkerLayer.BODY_CLASS);
    if (body != null && target.TryGetComponent<Enemy>(out var enemy))
        body.Add(
            new ProgressBar { name = "enemy-health",
                value = enemy.Health });
};
markers.MarkerHidden += (target, marker) =>
    marker.Q("enemy-health")?.RemoveFromHierarchy();

With a marker-template, add the part to an element of your template that you find by name or class.

How to give the markers your own look:

<tb:WorldMarkerLayer
    marker-template="project://database/Assets/UI/QuestMarker.uxml" />

The layer fills the elements named icon, label, distance and arrow of the template, when the template has them.

Member Description
Camera The camera of the game view. Null (the default) uses Camera.main.
Player The distances are from this object. Null (the default) uses the HudTarget with IsPlayer, else the camera.
Viewport The element that shows the render texture of Camera, or null when the camera draws on the screen.
ShowLabel (show-label) Shows the label of the target on its marker. On by default.
ShowDistance (show-distance) Shows the distance to the target on its marker. On by default.
DistanceFormat (distance-format) The format of the distance, with the meters as {0}. {0:0} m by default. A malformed format logs one warning and falls back to the default.
TargetMark (target-mark) None (the default), Box or Brackets. Draws a box or corner brackets around each target with a renderer that is on the screen.
FadeStart (fade-start) For a target with a MaxDistance, the marker fades out from this part of the max distance to the max distance. 0.8 (80 %) by default. 1 turns the fade off.
MarkerTemplate (marker-template) A UXML template for each marker. Null (the default) uses the built-in marker.
MarkerShown After a marker shows for a target. Add your own parts to the marker here.
MarkerHidden After the marker of a target hides, before the layer puts it back in its pool.
MarkerOf(target) The marker that shows for a target, or null.

Tips:

In the examples

Styling

Class Element
tb-world-marker-layer The layer: absolute, fills its parent.
tb-world-marker One marker: a point at the top of the target. It also has the class tb-hud--{kind} of its target.
tb-world-marker--edge A marker at the edge of the screen.
tb-world-marker__body The column of the icon, the label and the distance, above the point. At the edge, centered on the point.
tb-world-marker__icon The icon: 24 x 24 px.
tb-world-marker__label The label: bold, 15 px, on a dark plate, --tb-world-marker-text-color with an outline. --tb-color-danger for enemies and --tb-color-success for allies.
tb-world-marker__distance The distance: bold, 13 px, on the same plate.
tb-world-marker__arrow The arrow at the edge: a triangle in --tb-color-accent. It shows only with tb-world-marker--edge.
Variable Description
--tb-world-marker-box-color The color of the box or the brackets. --tb-color-accent by default.
--tb-world-marker-box-width The line width of the box, in pixels. 2 by default.
--tb-world-marker-box-corner The length of a bracket, in pixels. 14 by default.
--tb-world-marker-text-color The color of the label and the distance. Near white by default, since the plate is dark in every theme.
--tb-color-hud-outline The color of the text outline of the label and the distance. rgba(0, 0, 0, 0.8) by default.
/* Red brackets for a lock-on */
.hud-root .tb-world-marker-layer {
    --tb-world-marker-box-color: rgb(255, 60, 60);
    --tb-world-marker-box-corner: 20;
}

/* A larger icon for quests */
.tb-hud--objective .tb-world-marker__icon {
    width: 32px;
    height: 32px;
}