Skip to content

Custom camera preview

A custom camera does not replace the main view. It renders an OutputTexture that the module displays like any other texture.

local Preview = Cameras:CreateCamera()
if Preview == nil then
print("Camera limit reached")
else
Preview:SetRenderSize(320, 180)
Preview.Aspect = 320 / 180
Preview.Fov = 60
Preview:SetActive(true)
Scheduler:OnFrame(function()
local main = Cameras.Main
if main == nil then
return
end
Preview.Position =
main.Position + Vector3.new(0, 2, 0)
Preview.Rotation = main.Rotation
if Preview.OutputTexture ~= nil then
ImGui:DrawTexture(
Preview.OutputTexture,
Rect.new(20, 20, 320, 180)
)
end
end)
end
Preview:SetActive(false)

The texture keeps its final frame while rendering stops. SetActive(true) resumes updates.

if Preview ~= nil then
Cameras:RemoveCamera(Preview)
Preview = nil
end

Do not use the previous reference after removal.

Reference: Camera, Texture, and ImGui.