Hang a widget on an actor
Each local player has a world layer of their own.
Blueprint
- From the player controller, Get Local Player, then Get Local Player Subsystem of class Rolly Settings Core UI World Layer Subsystem, then Get World Layer.
- Create Widget with the player controller as its owner.
- Make Rolly Settings Core UI World Anchor: Component the actor’s root or a mesh, Offset 0, 0, 100 for a metre above it, Alignment 0.5, 1 to stand the widget on the point.
- Add Anchored Widget on the layer.
C++
URollySettingsCoreUIWorldLayerSubsystem* Layers = URollySettingsCoreUIWorldLayerSubsystem::Get(PlayerController->GetLocalPlayer());
// None on a dedicated server, or before the game viewport exists.
if (URollySettingsCoreUIWorldLayer* Layer = Layers != nullptr ? Layers->GetWorldLayer() : nullptr)
{
FRollySettingsCoreUIWorldAnchor Anchor;
Anchor.Component = Chest->GetRootComponent();
Anchor.Offset = FVector(0.0, 0.0, 120.0); // above the lid
Anchor.Alignment = FVector2D(0.5, 1.0); // the widget's bottom middle on the point
Anchor.OffScreen = ERollySettingsCoreUIAnchorEdge::Clamp; // Keep At Edge
Layer->AddAnchoredWidget(CreateWidget<UUserWidget>(PlayerController, MarkerClass), Anchor);
}The widget follows the component as it moves. Set Widget Anchor, or Add Anchored Widget again, hangs it elsewhere; Remove Anchored Widget takes it off.
| Anchor setting | What it does |
|---|---|
| Component, Socket | What the point follows: a component’s origin, or one of its sockets or bones. Empty: Location is a fixed point. |
| Offset | Added to the point in the world’s axes, in centimetres. |
| Alignment | The point of the widget on the anchor, as a share of its size: 0.5, 0.5 its centre. |
| Screen Offset | Moves the widget on screen, in layout units. |
| Off Screen | Hide, or Keep At Edge: the widget stays at the view’s edge on the side of its point, for points behind the camera too. |
| Keep Inside | Keeps the whole widget inside the view while its point is in view. Off: it may run past the edge. |
| Edge Margin | How far in from the edges it keeps (8). Below 0 counts as 0, so widgets never leave the player’s view. |
| Max Distance | Hides the widget farther than this from the camera, in centimetres. 0: at any distance. |
| Z Order | A higher one draws above; of equal ones, the nearer draws above. |
Point an edge marker at its target
On Anchor Changed fires when a widget shows or hides, reaches the view’s edge or leaves it, or turns past a sixteenth of a turn while at the edge. Its state’s Direction points from the view’s centre toward the target: turn an arrow in your widget with it. Get Anchor State gives the same at any time, with the widget’s place and the camera’s distance.
Keep markers in each player’s view
Each player’s layer covers that player’s part of the screen and projects through that player’s camera, so two players see their own markers. Widgets keep to the player’s view within the display’s title-safe area: in a split, only the screen’s outer edges take the safe margin, never the line between the players. Layout units follow the interface’s scale, as in the rest of your UI.
Know when widgets leave
- A component that leaves play (its actor destroyed, the component unregistered, its level streamed out) takes its widget off the layer: On Anchor Dropped tells you.
- The map’s end takes the layer away with its widgets, each dropped; the next map makes a new layer the first time one is asked for. Get World Layer gives none while the map ends, so anchor again in the next map, not in On Anchor Dropped.
- Remove All Widgets, or Remove from Parent on the layer, takes the layer off the screen: its widgets are dropped, and the next Get World Layer makes a new one.
- A layer without widgets collapses and does no work; one with widgets places them once a frame.
Hide the markers for a while
Set Visibility Hidden on the player’s layer (a cutscene, a photo mode) hides every widget on it as widgets come and go; Self Hit Test Invisible shows them again.
Change the layer’s order and size
Project Settings > Plugins > Rolly Settings Core UI > World Layer:
| Setting | What it does |
|---|---|
| World Layer Z Order | Where each player’s layer draws among their widgets: -10, below a HUD added at 0. The Rolly screens draw above it. |
| Max World Anchors | The most widgets one player’s layer holds (256); widgets past it are refused, with one setup message however many. |
Limits
- Widgets show over walls: the layer does not test whether the point can be seen.