Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facepunch/sbox-public/llms.txt
Use this file to discover all available pages before exploring further.
CameraComponent is s&box’s primary rendering component. Attach it to any GameObject to define a viewpoint — it controls projection, clipping planes, background color, post-processing, and HUD rendering. Every scene needs at least one active camera. This page covers all properties and methods available on CameraComponent.
Adding a camera
AddCameraComponent to a GameObject in the editor or create it in code.
Properties
Projection
The horizontal (or vertical) field of view in degrees. Valid range is 1–179. Has no effect when
Orthographic is true.Controls which screen axis
FieldOfView is measured along. Axis.Horizontal fits the view within the horizontal extent of the screen; Axis.Vertical fits it vertically.When
true, the camera uses orthographic projection instead of perspective. FieldOfView and FovAxis have no effect.The world-space height of the orthographic view frustum. Only relevant when
Orthographic is true.Near clip plane distance. Anything closer than this distance is not rendered. Keep this value at 5 or above — values below 1 cause z-fighting artifacts.
Far clip plane distance. Anything beyond this distance is not rendered. Sensible values are 1 000–30 000; you can push further by raising
ZNear proportionally.Camera priority and viewport
Marks this camera as the main game camera. The scene exposes the highest-priority main camera via
Scene.Camera.Determines render order when multiple cameras are active. Higher values render on top. Range is 1–16.
Normalized screen rectangle
(x, y, width, height) in the 0–1 range. Use this to create split-screen or picture-in-picture effects.Read-only. The viewport rectangle in screen pixels, derived from
Viewport and the current screen size (or CustomSize).Appearance
The solid color used to fill the background when no sky is present and
ClearFlags includes ClearFlags.Color.Controls which buffers are cleared before rendering. Defaults to clearing color, stencil, and depth.
Only objects whose tags match at least one tag in this set are rendered. Leave empty to render all objects.
Objects whose tags match any tag in this set are excluded from rendering.
Render targets
When set to a valid render-target texture, the camera outputs to that texture instead of the screen. Create one with
Texture.CreateRenderTarget().An asset-based alternative to
RenderTarget. Mipmaps are regenerated automatically after rendering when the texture has more than one mip level.Optional override for the camera’s output size. When
null, the camera uses the screen size or the render target’s size.Post-processing
Enables or disables post-processing for this camera. Disabling skips bloom, auto-exposure, volumetric fog, and all other post-process volumes.
When set, post-process volumes are sampled from this object’s position instead of the camera’s position. Useful for third-person cameras.
Advanced projection
Optional override for the camera’s projection matrix. Set to
null to use the standard perspective or orthographic matrix.Read-only. The current projection matrix, either the custom one or the computed standard matrix.
The HMD eye this camera targets. Use
StereoTargetEye.None for the main monitor (companion window).HUD and overlay
CameraComponent exposes two HudPainter accessors for immediate-mode drawing directly into the camera’s output.
A painter that draws before post-processing. Use this for in-world overlays that should be affected by post-process effects.
A painter that draws on top of everything, including the UI. Useful for debug visualizations and always-visible HUD elements.
Hud and Overlay are component-level properties — access them on your CameraComponent reference, not statically.Methods
Screen-space utilities
Converts a world-space position to normalized screen coordinates (0–1 range).
Converts a world-space position to screen pixel coordinates.
Like the overload above, but also outputs
isBehind — true when the point is behind the camera.Computes the screen-space bounding rectangle that fully contains the given world-space
BBox. Sets isBehind when all corners are behind the camera or off-screen.Returns a world-space ray from the camera through the given screen pixel. Use this for mouse picking.
Like
ScreenPixelToRay but accepts normalized screen coordinates.Converts a screen position to a world-space point on the near frustum plane.
Frustum
Returns the view frustum for the current viewport.
Returns the view frustum for a custom pixel rectangle within the viewport.
Returns the view frustum with a custom screen-size reference. Pass
Vector3.One to use normalized coordinates.Rendering to a texture
Renders the scene from this camera’s viewpoint into
target. Returns false if target is null or invalid. Use a texture created with Texture.CreateRenderTarget().Renders the scene into a
Bitmap. The bitmap must be at least 2×2 pixels.Projection helpers
Computes a projection matrix with an oblique near clip plane defined in world space. Useful for portal or mirror rendering.
Pushes all settings from this component onto a
SceneCamera instance. Called automatically each frame; useful when you manage your own SceneCamera.Usage examples
- Mouse picking
- World-to-screen
- Render to texture
Related pages
Rendering guide
Overview of s&box’s rendering pipeline and how cameras fit in.
UI panels
Building HUD panels with ScreenPanel and Razor UI.
Light components
DirectionalLight, PointLight, SpotLight, and environment probes.
Shaders guide
Writing custom shaders and reading render attributes from cameras.