Home › Modules › AFM_Spectator
Module

AFM_Spectator

Spectator cameras from one component: a live feed from any actor, Fixed, Look At and Follow camera modes, and one live camera shown on the headset's spectator screen in VR or in a picture-in-picture panel on desktop.

What it gives you

  • A live camera feed from any actor, with one component
  • Fixed, Look At and Follow camera modes with smoothing
  • One live camera for streams and trade-show screens, switched by key or from your own logic
  • Monitors in the world that show a camera's own feed

Requires

AFL_Libraries AFM_Settings AFS_UI AFS_UI_InfoPanels

Required by

AF_Examples

4 assets27 API members

Description

A VR headset view makes poor video: it is shaky, cropped and mono. AFM_Spectator gives you a second, steady camera for demos, trade shows and recordings, and screens in the world that show it.

BPC_Spectator is the whole camera. Add it to any actor: it captures its own feed into a render target at Capture Rate and can stay where it was placed, turn towards a target or follow it. It derives from AFSSceneCaptureComponent2D, a small C++ scene capture in AFS_Libraries that Blueprints can inherit from; a camera component would not tick in packaged builds, which leaves the feed black there. Field of view and post-process are the component's own Scene Capture settings.

Cameras with Register As Spectator on join BPC_GameState_SpectatorManager, which the first camera adds to the game state. Activating a registered camera makes it the live camera and stops the previous one. In VR the live feed goes to the headset's spectator screen (the desktop mirror), laid out by the camera's Capture Mode; on desktop and mobile it opens WBP_Spectator_PiP as an info panel on the HUD. BP_Spectator is a ready-made camera with its own small monitor.

Setup

  1. Place BP_Spectator, or add BPC_Spectator to an actor of your own and aim it.
  2. Pick a Camera Mode. For Look At and Follow, set Target Actor, or turn on Watch Player to watch the local player.
  3. For a camera that should become the live camera, keep Register As Spectator on and turn Auto Activate off, so it waits until it is switched to.
  4. For a monitor or CCTV view that always renders, turn Register As Spectator off and leave Auto Activate on.
  5. To show a feed on a mesh, give it M_Spectator_Screen and set its Screen Texture to the camera's Get Render Target, as BP_Spectator does.
A spectator camera with its settings
AFM_Spectator_setup.pngA spectator camera with its settings
A spectator camera with its settings

Usage

Switching the live camera

Page Down, Page Up and End switch to the next or previous registered camera or stop the live one (IMC_Spectator, added for the local player by the manager). From your own logic call Activate on a camera, or Activate Next, Activate Previous and Deactivate Active Spectator on the manager. Bind On Active Spectator Changed to follow the switches, as the director panel in the example does.

Camera modes

Fixed stays where it was placed. Look At stays in place and turns towards the target. Follow moves along with the target at Follow Offset (turned with the target's facing only, not its head tilt) and looks at it. Aim Offset is added to the target's position to frame head and shoulders; Smoothing sets how quickly the camera catches up (0 follows exactly, head shake included).

Monitors in the world

M_Spectator_Screen cancels the scene's exposure and tone curve, so a monitor shows the scene at its own brightness. Brightness scales it; Tone Compensation 0 turns the correction off.

The spectator view alongside the headset view
AFM_Spectator_result.pngThe spectator view alongside the headset view
The spectator view alongside the headset view

Key properties

PropertyWhen to change
Camera ModeFixed, Look At or Follow
Target Actor / Watch PlayerWhat Look At and Follow watch: an actor, or the local player
SmoothingHow calm the footage is
Follow Offset / Aim OffsetWhere Follow sits and what it frames
Capture RateCaptures per second while active (default 30; 0 every frame)
Spectator Screen SizeResolution of the feed, fixed at the first capture
Register As SpectatorCan become the live camera; off for monitors that always render
Capture ModeSpectator screen layout in VR: feed only, or feed and headset view combined
FOV AngleField of view (Scene Capture settings)

Extending

Bind On Active Spectator Changed on BPC_GameState_SpectatorManager to build your own director or overlay, and use a camera's Get Render Target for your own screens. Keep custom capture logic in BPC_Spectator or a subclass of it: Event Tick in a Blueprint based on a camera component does not run in packaged builds.

Performance notes

Performance

Every capture is a full extra render of the scene. Keep Capture Rate low (15–30) and Spectator Screen Size modest on standalone headsets, and remember that cameras with Register As Spectator off capture all the time.

Example map

Map_Examples_Spectator has four stations: a camera with its own monitor, the three camera modes side by side, switching the live camera from a director panel, and a camera that follows a drone.

Troubleshooting

The feed is black in a packaged build. The editor modules and the game were built without the AFS_Libraries C++ code. Rebuild the plugin modules; BPC_Spectator needs AFSSceneCaptureComponent2D.

A camera does not become the live camera. It is not registered, or it was already active when it registered. Keep Register As Spectator on and turn Auto Activate off.

No picture-in-picture on desktop. The panel opens through the HUD; the pawn needs BPC_PawnAbility_HUD.

API reference

Every blueprint asset in this module. Expand an asset to see its members.

Blueprints

BP_Spectator0 members
extends Actor

Spectator camera with its own monitor: a BPC_Spectator (Fixed, 30 captures per second, 1280 x 720) that shows its feed on the small screen below it, which uses M_Spectator_Screen. The screen faces the way the camera looks, so people in front of it see themselves. Register As Spectator is off, so it keeps rendering when the live spectator camera is switched elsewhere. Set Camera Mode on the placed camera to make it turn towards or follow its target.

No editor-visible members; this asset configures defaults only.

Components

BPC_GameState_SpectatorManager10 members
extends ActorComponent

Spectator manager on the game state: keeps the list of registered spectator cameras (BPC_Spectator with Register As Spectator) and which one is live. The first camera that needs it adds it to the game state, so nothing has to be set up. Activating a registered camera makes it the live camera and stops the previous one: in VR its feed goes to the headset's spectator screen in the camera's Capture Mode layout, on desktop and mobile it opens WBP_Spectator_PiP as an info panel on the HUD. Page Down, Page Up and End (IMC_Spectator, added for the local player at Begin Play) switch to the next or previous camera or stop; call Activate Next, Activate Previous and Deactivate Active Spectator from your own logic, and bind On Active Spectator Changed to follow the switches.

KindNameSignatureDescription
fnensureMirror()Creates Mirror Render Target and Mirror Material the first time they are needed; does nothing once they exist.
fnupdateMirror()In VR with a live camera: draws the camera's picture into Mirror Render Target for the headset's spectator screen. Runs on tick (every 0.0333 s, about 30 per second) and when a camera goes live; does nothing without a headset or a live camera.
fnOnComponentDeactivated_Event(Component: ActorComponent)Runs when a registered camera is deactivated: if it was the live camera, the headset's spectator screen goes back to the normal mirror (or the picture-in-picture panel closes) and Active Spectator is cleared.
fnOnComponentActivated_Event(Component: ActorComponent, bReset: bool)Runs when a registered camera is activated: makes it the live camera, shows its feed (headset spectator screen in VR, picture-in-picture info panel without a headset), fires On Active Spectator Changed and then stops the camera that was live before.
fnDeactivateActiveSpectatorDefault()Stops whichever camera is live. Bound to End.
fnActivatePreviousDefault()Switches to the previous registered camera, wrapping round; with none live it starts the last. Bound to Page Up.
fnActivateNextDefault()Switches to the next registered camera, wrapping round; with none live it starts the first. Bound to Page Down.
eventRegisterSpectator(Spectator: BPC_Spectator)Adds a spectator camera to the list and listens to its activation, so activating it makes it the live camera. BPC_Spectator calls it at Begin Play when Register As Spectator is on.
eventUnregisterSpectator(Spectator: BPC_Spectator)Removes a spectator camera from the list and stops listening to it. BPC_Spectator calls it at End Play, so cameras in unloaded levels drop out of the switching order.
eventOnPossessedPawnChanged_Event(OldPawn: Pawn, NewPawn: Pawn)Runs when the local player switches pawn. After a second, which lets the new pawn finish setting up, it re-activates the live camera, so the feed follows the new pawn.
BPC_Spectator15 members
extends AFSSceneCaptureComponent2D

Scene capture component (AFS Scene Capture 2D) that renders its own live feed into a render target it creates at Spectator Screen Size. Captures from Event Tick at Capture Rate while active; field of view, post-process and the other capture settings are its own Scene Capture settings. Camera Mode keeps it where it was placed, turns it towards a target or follows the target; the target is Target Actor, or the local player when Watch Player is on. With Register As Spectator on it joins the spectator manager on the game state, and activating it makes it the live camera: on the headset's spectator screen in VR, in the picture-in-picture info panel on desktop. Add it to any actor; nothing else is needed. Inherits from a scene capture (not a camera) because a camera component does not tick in packaged builds.

KindNameSignatureDescription
varSpectator Screen SizeSettingsVector2Dresolution in ptx of the live feed the spectator component provides
varRegister as SpectatorSettingsboolJoin the spectator manager at begin play, so this camera can become the live camera. A registered camera that gets activated becomes the live camera and the previous one is deactivated. Turn it off for monitors and CCTV cameras that must keep rendering all the time.
varCapture ModeSettingsE_Spectator_CaptureModeLayout of the headset's spectator screen (the desktop mirror) while this camera is live. Entire Screen shows only the feed, Texture Top Right shows the headset view with the feed in the corner, Eye Top Right shows the feed with the headset view in the corner. Not used without a headset.
varCapture RateSettingsfloatCaptures per second while the camera is active, applied as the component's tick interval at begin play. 30 by default; 0 captures every frame. Each capture is a full extra scene render, so keep it low on standalone headsets.
varTarget ActorCameraActorActor that Look At and Follow watch, for example a vehicle or a demonstrator. When empty, Watch Player decides whether the local player is watched.
varSmoothingCamerafloatHow quickly the camera catches up with its target in Look At and Follow. Lower values give calmer footage; 0 follows exactly, head shake included.
varFollow OffsetCameraVectorWhere the camera sits in Follow mode, relative to the target and turned with its facing only (not its head tilt). X is forward, Y right, Z up; the default is behind and over the right shoulder.
varAim OffsetCameraVectorAdded to the target's position to get the point the camera looks at in Look At and Follow. The default aims a little below the eyes, so head and shoulders are framed.
varCamera ModeCameraE_Spectator_CameraModeHow the camera moves while it is active. Fixed: stays where it was placed. Look At: stays in place and turns towards the target. Follow: moves along with the target at Follow Offset and looks at it. The target is Target Actor, or the local player when Watch Player is on.
varWatch PlayerCameraboolWhen Target Actor is empty, Look At and Follow watch the local player's view (the headset in VR). Off: without a Target Actor the camera stays as placed.
fnupdateCamera(DeltaSeconds: float)Moves and turns the camera for Camera Mode, smoothed by Smoothing. Look At turns towards the target, Follow moves to the target plus Follow Offset and turns towards it, Fixed does nothing. Nothing moves while there is no target. Called every tick before the capture.
fngetSpectatedView(out Location: Vector, out Rotation: Rotator, out Valid: bool)Returns where the watched view is and which way it faces, yaw only: Target Actor's location and facing when one is set, otherwise the local player's camera (the headset in VR) when Watch Player is on. Valid is false when there is nothing to watch.
fngetRenderTarget(out RenderTarget: TextureRenderTarget2D)Returns the render target the feed is captured into, creating it at Spectator Screen Size with a target gamma of 2.2 if it does not exist yet. Cached afterwards, so the resolution is fixed at the first call.
fngetSpectatorManager(out SpectatorCoordinator: BPC_GameState_SpectatorManager)Returns the spectator manager (BPC_GameState_SpectatorManager) on the game state, adding it there the first time and caching it. Returns none while there is no game state yet, which happens briefly on clients.
eventEnd Play(EndPlayReason: EEndPlayReason)Unregisters this camera from the coordinator, so it drops out of the switching order when its level is unloaded.

Widgets

WBP_Spectator_PiP2 members
extends WBP_Base

Picture-in-picture of the live spectator camera for desktop and mobile, where there is no headset spectator screen. Sits in the top-right corner at about 30% of the screen width, keeps the feed's aspect ratio and ignores the mouse. Created and shown by the spectator coordinator when a camera becomes live without a headset, hidden when it stops.

KindNameSignatureDescription
eventWidgetElement_PostInitiateStyle()Called on every element once the entire tree has been initiated and themed. Implement it for set-up that needs the finished tree, such as measuring or reading the state of a sibling.
eventOnActiveSpectatorChanged_Event()Runs when another camera goes live and shows its feed in the picture-in-picture image.