Log inGet started

Cameras — which one is rendering, with what projection, into what

Updated December 6, 2026

A physical camera on the machine (a webcam, a phone's front or back camera) is camera input: cameraInput.open() shows its live picture as a texture, and topics/camera-input covers it.

One snapshot per drawn frame

The observation is published once per frame that is drawn, from after the frame is drawn. So a read describes the last frame, not the state of the world at the instant of the call: a write to a camera and a read of the observation in the same script step return the frame that ran before the write. To compare a camera before and after a change, put a frame between them:

local before = camera.get(camId)
entity(camId).component.get("Camera").fov = 35
task.wait()                                  -- let a frame be drawn
local after = camera.get(camId)

camera.observe().frame is the renderer's frame the observation describes, so two reads that report the same number are one frame, a poll can wait for it to advance, and it is measured on the same clock as the frame every renderer.cullStats().views row names. A frame the frame pacer holds back draws nothing and publishes no observation; the last one stands.

The field of view on every screen shape

A camera's fov is an angle in degrees across one side of the frame, and its fovAxis names the side. The default, "shorter", holds the angle across the frame's narrow side: upright on a landscape screen and across the width on a portrait one, so a phone held upright sees as much to either side of the player as a desktop sees above and below it. "vertical" and "horizontal" hold the angle on that side at every shape. camera.viewData() reports the vertical angle the frame was drawn at (fovY), and camera.verticalFov(fov, fovAxis, aspect) answers it for any shape. The Camera component README has the table.

The player's own camera settings

A player sets their camera and controls once, in the Camera and controls section of the pause menu's System tab, and keeps them in every world: look speed and inverted vertical look for the mouse, the controller stick and touch, the field of view, reduced camera motion, the stick dead zone, and whether the camera turns back behind them on its own. camera_settings (require("@builtin::modules.api.engine.camera_settings")) states them and applies them:

  • a camera behavior (the Controllers library's camera rigs among them) runs each look through camera_settings.look(dx, dy, class) (the class is the look control's onInput fourth argument), waits out camera_settings.recenterDelay(delay) before turning back, and scales the lead and head motion it adds on its own by camera_settings.motion();
  • the Camera component draws a perspective camera on the viewport at camera_settings.fieldOfView(fov), the player's degrees added to its own fov, which itself stays as authored;
  • a pad stick binding with no deadzone of its own reads through the player's dead zone.

A world's own camera code reads them the same way, so the player's choices reach it too: pass each look through camera_settings.look, shake the camera through its effect layer (below), which shows no shake while the player asks for reduced motion, and read camera_settings.current() for the rest. clientSettings.open("camera") opens the section. A world reads the settings and never changes them: they are the player's.

Shake, impulses, landing dips and field-of-view kicks

Every Camera component carries an effect layer that adds motion to the pose its behavior gives it, in any rig, from any script, at any executionOrder:

local cam = entity(camera.active()).component.get("Camera")
cam:shake(0.4)                                  -- trauma 0..1, decays by itself
cam:impulse({ turn = { x = 2 }, decay = 14 })   -- a kick: degrees of pitch/yaw/roll
cam:land(fallSpeed)                             -- a landing dip that springs back
cam:setFov("sprint", 8)                         -- stacked over the authored fov
cam:setFov("sprint", nil)                       -- released, eased back
cam:setOffset("lean", { x = 0.3 }, { z = -6 })  -- held until set to nil
cam:setMotion({ speed = 1, grounded = true })   -- head bob and idle breathing

The layer moves the drawn view rather than the transform: the renderer composes it over the pose the behavior wrote (ecs.Camera's viewOffset* and viewTurn*, and camera.viewData() reports the composed view), so the behavior reads back its own pose and nothing has to undo the shake before the rig runs again. Field-of-view sources each add degrees to the camera's own fov, which the layer never writes, so they stack and release in any order back to it. effectProfile tunes every channel (realistic, cinematic, intense, minimal, drunk, or a world's own from camera_effects.registerProfile), and cam:effects() reads what the layer shows. The player's reduced camera motion setting shows no shake, impulse, head bob or breathing.

Aiming a camera at something

A camera parked on a station has an eye point and a look point, and the orientation between them is lookAt on the camera's own entity proxy:

local cam = entity.spawn("FilmCamera")
cam.localPosition = { 0, 1.35, -16 }
cam:lookAt({ 0, 4.5, 8 })                 -- a point
cam:lookAt(subject)                       -- or whatever it is filming
cam:lookAt(subject, { 0.2, 1, 0 })        -- ... rolled into a dutch tilt

A camera looks down its entity's forward — its local -Z — which is the axis lookAt aims, so the aim and the shot agree. It writes the WORLD rotation, so a camera parented to a rig or a dolly still lands on the point named. The trailing up hint decides the roll; world +Y stands in when it is left out, and a target directly overhead or directly below is an ordinary case.

For a camera driven per frame from a component, the same call reads the same way in update, and the orientation on its own — transform.lookRotation(eyeX, eyeY, eyeZ, atX, atY, atZ) — hands back the four quaternion components when the pose is being blended rather than written.

Why is this camera not showing what I expect

camera.observe() returns every camera in the world, for the frame that has just been drawn. Each carries rendering, and when that is false a reason naming the one cause:

for _, cam in ipairs(camera.observe().cameras) do
  if not cam.rendering then
    print(cam.name, "is dark because:", cam.reason)
  end
end

The reasons are a closed set — every camera that drew nothing resolves to exactly one, and each is a state the engine reads rather than infers:

reasonWhat it means
disabledCamera.enabled is false, so the camera never competes for the viewport or renders into a target.
entityInactiveThe camera's entity, or an ancestor of it, is deactivated.
targetMissingThe camera names a render target that has no surface. Create it with renderer.texture.create before pointing a camera at it.
noLayersThe camera's render-layer mask is empty, so every object fails its membership test.
outrankedAnother camera won the viewport. camera.observe().viewport.camera names the winner.
notDrawnThe camera was scheduled and the renderer produced no draw for it.
pacedThe frame pacer held this frame back while the frames before it are still on the GPU (renderer.framePacing() counts them in pacedFrames), and the camera's per-frame render into its texture is drawn on the next frame the pacer admits. lastRender names the frame it last drew.
awaitingPipelinesThe camera's one-shot render — a capture, a preview, a readback — is queued behind pipeline builds the scene asked for, and is taken the frame they land. pipelinesPending counts what it waits on, so a poll can tell a queue that is draining from one that is stuck — and a camera that DID draw carries it too, naming the builds the frame it drew was drawn WITHOUT, so one frame can be told from a frame of the settled scene.

A camera that rides or chases a moving body

A camera moves with what it frames through its behavior: the component the Camera's behavior field attaches, and every component carrying the cameraBehavior tag is one the field accepts (layers.active.camera.behaviors._list() lists the installed ones). The Controllers library publishes ready ones as its cameraRigs package, beside its character and car controllers: install it with world.installLibrary({ world = "034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" }) (a ZeroMind search for Controllers or a follow camera finds it), and each behaviour is named @controllers:: followed by cameraRigs.<name>: an orbit follow, an over-the-shoulder follow, a first-person camera, a chase camera, a seat camera that rides a body (a cockpit, a hood view, a turret sight), and strategy, isometric, overhead, side-scrolling and cutscene cameras. Its choosing-a-camera guide says which behaviour fits which game, and each behaviour's README lists its fields, its controls and how it keeps out of walls. A new world made with the clearing or player start installs it.

local camera = entity.find("cam").component.get("Camera")
camera.behavior = asset.ref("@controllers::cameraRigs.chase", "component")
camera.follow = car

A behavior reads the entity it frames from Camera.follow, so one camera switches between views by writing its behavior; a swap attaches the new behavior fresh with its defaults, so a view's tuning is set after the write. A behavior that follows a moving body places the camera from where the body is drawn this frame (Physics.drawnPose), so a body the simulation moves between ticks holds still on screen at any frame rate and tick rate.

What the frame was drawn with, and what the component holds

Every camera carries two projections. authored is what the Camera component holds; frame is what the renderer built for the frame just drawn. mismatch names every field the two disagree on:

local cam = camera.get(camera.active())
print(cam.authored.far, cam.frame.far, table.concat(cam.mismatch, " "))

A non-empty mismatch says a value content wrote is not the value the frame was drawn with. Reading the pair is the whole point of the surface: it replaces unprojecting the inverse view-projection matrix by hand to find out what the clip range really was.

frame, viewProj, frustum and the cost numbers describe a camera that drew. A camera with rendering = false carries authored, its identity, its layers and its reason, and leaves those four out.

What each camera renders into

output says where a camera's pixels go — kind is "viewport" or "texture", target is the render-target guid for a texture camera, and width / height are the pixel size actually drawn into:

for _, cam in ipairs(camera.observe().cameras) do
  print(cam.name, cam.output.kind, cam.output.target, cam.output.width, cam.output.height)
end

Which render layers a camera resolves to

layers is the set of named render layers a camera's mask includes, and layerMask is the raw mask. A camera whose spec names a layer nothing is a member of draws nothing while every other reading looks healthy — the layer set beside a cost.drawCalls of zero is what says so.

all means every layer, EditorUI and debug included — the editor's own chrome and the debug overlays. A camera an author writes "all !ui" for resolves to default debug sky EditorUI, and draws a gizmo or a debug overlay whenever one is up. A camera whose frames a player or a reviewer sees wants those two named out. A report is a reading, so the spec is written through the camera's entity:

local report = camera.get(camera.active())
entity(report.entity).component.get("Camera").renderLayers = "all !ui !EditorUI !debug"

Read layers back to see which spec resolved to what.

A layer a camera names is only half of it — the other half is which entities are on that layer, written with renderLayer.set ({ tree = true } for a whole hierarchy) and read with renderLayer.get. The render-layers guide covers both, and renderLayer.list shows every layer with its members and the cameras that include or exclude it.

What each camera costs

cost is for the one frame the observation describes, not a sum since a reset:

for _, cam in ipairs(camera.observe().cameras) do
  if cam.rendering then
    print(cam.name, cam.cost.cpuMs, cam.cost.drawCalls, cam.cost.drawInstances)
  end
end

cpuMs is wall time around the render that camera submitted. drawCalls and drawInstances are the renderer's own draw counters read either side of that submission, so they count the draws that camera issued — the per-camera answer to "the frame got slow after I added the minimap". A camera the frame drew more than once — its own target plus a target Camera:render(guid) named in the same frame — reports every one of those renders together.

submits is the renderer's queue submissions read the same way. A submission costs the same whatever it draws, so it is what a camera drawing a tiny target still pays. A camera drawing into a texture submits its whole render together; one that composites a screen submits its scene, its post-processing and its display transform ahead of the screen, then the screen, then the pass carrying the picture to the texture.

Where the time of the frame's texture-camera renders goes, stage by stage, is in profiler.stats() under system.schedule.render.render_offscreen_cameras. (shadows, cull, post_display, scene_submit and the rest), each summed over that frame's renders. scene_finish is the encoding of those renders' commands; in a native build, while a reader times the frame (a frame-cost window, a recording), the stages under it state the kinds of work in it (scene_finish.render_pass, scene_finish.compute_pass and the rest), each pass kind holds one row per pass label with the stages spent inside those passes beneath it (scene_finish.render_pass.scene/shadow/raster.draw, a label's dots written as /), and profiler.counters counts the render and compute passes the renders recorded under scene_finish.render_pass.runs and scene_finish.compute_pass.runs.

renders is how many of them that is, so the figures beside it divide into a per-render cost. A frame draws the renders it can afford and queues or drops the rest, so how many a camera got is the frame's answer rather than the caller's: read renders on the frame in hand instead of counting the renders you asked for.

local row = camera.observe().cameras[1]
if row.cost.renders > 0 then
  print(("%.2f ms over %d render(s)"):format(row.cost.cpuMs, row.cost.renders))
end

Summed over the cameras that drew, they account for renderer.drawStats().draws whenever every render in the frame belongs to a camera. A viewport no camera won is still drawn, from the pose the renderer last held, and is credited to none — so on such a frame the sum is short by what that render cost.

The whole inventory, and one camera

  • camera.observe() — the whole observation, including the viewport's owner and pixel size.
  • camera.list() — just the per-camera reports, highest priority first.
  • camera.get(entityId) — one camera's report.
  • camera.viewData(entityId) — one camera's view data: position, projection, the near and far clip planes its frame was drawn with (near, far: the planes a pass turning its depth into distance reads), viewport size, the 6 world-space frustum planes and the view-projection matrix, plus which camera it describes, what it rendered into and its layers. Called with no argument it is the viewport camera's, which is the form a render feature reads per frame.

Which way a camera faces

entity(id).transform.forward is the entity's own transform. The Camera component's forward, right and up are the facing the person looking through the camera sees: the same vectors, except for the on-screen camera during an XR session. There the camera is the rig, the game's position and yaw, and the person looks along the rig turned by their head, so the component reports that view. Anything that moves or aims relative to the camera reads the component (the character controller does) and follows the view in a headset unchanged. The rig is composed from the entity's transform, so turning the head never turns the camera. camera.facing(id, axis) is the same read by entity id and answers nil where the entity's own transform is the facing.

A walk that steers by the camera

A frame's component updates run in this order: look, camera-relative intent, the character controller, the camera's placement around its subject. The Camera component runs in the look phase (executionOrder -105) and calls look(dt) on every component on its entity that declares one: the behavior its behavior field attached and a rig added to the entity directly with component.add alike. An error a look raises is logged naming that component and recorded on its errors. The behavior takes the frame's look and zoom controls and its recentre there and turns the camera to face its framing. Everything that steers by the camera's facing runs after it, a walking input writer (-103) and a character controller (-100) among them, so a walk relative to the camera moves along the facing the frame is drawn with, on the frame a look turns it, from a mouse, a stick or a finger alike. The behavior's update (-90) then places the camera around its subject where the subject has moved to, keeping the facing its look turned it to.

A behavior that turns the camera on look input declares look(dt), takes its look there and faces the camera; it runs once a frame, so its own update calls it too for a frame the Camera did not. The Camera asks each component for look on every frame, so an edit that adds or removes it is followed as soon as the edit reloads the component. A component that steers by the camera reads the facing from an executionOrder greater than -105, so it runs after the look.

Which camera owns the viewport

  • camera.active() — the camera drawing the screen this frame.
  • camera.main() — the highest-priority scene camera, never the editor fly-cam.
  • camera.editor() — the editor fly-camera.
  • camera.setEditorOverride(id) — give one camera the viewport outright, ignoring priority; nil clears it.

The viewport is decided by priority, highest wins, within the participation the camera competes in — an EditorOnly camera and a scene camera are elected separately, which is what keeps an authoring fly-cam above a scene's own cameras at any priority.

From the filesystem

The same observation is served at /zero/runtime/cameras, one entry per camera entity:

vfs.list("/zero/runtime/cameras")          -- one entry per camera entity
vfs.read("/zero/runtime/cameras")          -- the whole observation as JSON
vfs.read("/zero/runtime/cameras/" .. camId) -- one camera's report

Both surfaces serialise one published snapshot, so they can never disagree.