For the complete documentation index, see llms.txt. This page is also available as Markdown.

Vision usage examples

Find code patterns for common Vision setups, including safety training, webcam selection, look-at activation, on-demand triggers, and WebGL deployment.

These examples cover the most common Vision integration patterns. Each example is self-contained — copy the relevant script, attach it to the appropriate GameObject, and configure the serialized fields in the Inspector.

Monitor object placement in safety training

A safety training application where a Convai character monitors whether the user places equipment in the correct zone and gives spoken feedback. The character uses the live scene camera feed to observe placement in real time.

Expected outcome: When the player moves an object, the character describes its position and confirms whether placement is correct or flags a safety issue.

using Convai.Modules.Vision;
using Convai.Runtime.Vision.Publishing;
using UnityEngine;

/// <summary>
/// Enables vision when the training sequence starts and disables it when complete.
/// Attach to the same GameObject as ConvaiVisionPublisher.
/// </summary>
public class SafetyTrainingVisionController : MonoBehaviour
{
    [SerializeField] private ConvaiVisionPublisher _publisher;

    void Awake()
    {
        // Start in Manual mode so vision only captures during active training
        _publisher.SetPublishPolicy(VisionPublishPolicy.Manual);
    }

    public void BeginTrainingSequence()
    {
        _publisher.SetPublishPolicy(VisionPublishPolicy.HighResponsiveness);
        _publisher.EnablePublishing(true);
    }

    public void EndTrainingSequence()
    {
        _publisher.EnablePublishing(false);
        _publisher.SetPublishPolicy(VisionPublishPolicy.Manual);
    }
}

Select webcam device at runtime

A desktop onboarding application where the user selects which physical camera to use before a session starts. Useful when the user's workstation has multiple cameras (built-in webcam, USB camera, etc.).

Expected outcome: The dropdown populates on Start with all detected camera names. Selecting a camera name and clicking Switch swaps the capture device without stopping the session.

TMP_Dropdown requires the TextMeshPro package. If your project uses the legacy UnityEngine.UI.Dropdown, replace TMP_Dropdown with DropdownAddOptions(List<string>) works identically.

Stream an overhead security camera

An architectural walkthrough where an overhead security camera monitors the entire floor plan. The publisher uses LowOverhead policy because the scene changes slowly and bandwidth must be reserved for audio.

Expected outcome: The character describes what is visible in the top-down view — furniture layout, occupancy, or hazards — when asked.

Assign the overhead camera to the Target Camera field on the CameraVisionFrameSource component in the Inspector. CameraVisionFrameSource.TargetCamera has a private setter, so a script cannot repoint the frame source to a different camera at runtime — the Inspector field is the only supported way to choose which camera it reads.

Activate publishing on player look-at

Vision is expensive to stream continuously. This pattern activates publishing only while the player is looking at a specific object (e.g., a piece of machinery), and pauses it otherwise.

Expected outcome: The character responds to the object's state only when the player is looking at it. Network and GPU overhead are zero when the player looks away.

Configure Vision for WebGL

On WebGL, no frame source component is required. ConvaiVisionPublisher captures the browser canvas automatically via canvas.captureStream(). Set Connection Type to Video and the publish policy as needed — everything else is automatic.

Expected outcome: The character receives a live feed of the browser canvas. No frame source component is on the scene.

Trigger vision on demand and adjust respond mode

The previous examples all publish frames continuously through ConvaiVisionPublisher. A separate, lower-level surface on IConvaiRoomConnectionService lets you ask the backend to inspect the buffered frames on demand — independent of the publisher's own cadence — and control whether that inspection makes the character speak. This pattern fits a "Look now" button, an inspection tool the player triggers manually, or a step in a scripted sequence that needs a vision check at a precise moment.

RequestVisionStatus() asks the backend to report the state of the session's frame buffer. TriggerVision(ConvaiVisionTriggerRequest) asks the backend to attach buffered frames to the next turn and, depending on the request's respond mode, invoke the model. UpdateRespondMode(ConvaiRespondModeLane, ConvaiRespondMode) changes how an entire input lane affects the character's speech for the rest of the session. All three are acknowledged asynchronously through domain events rather than a return value — see Vision scripting API for the full method signatures, request fields, and event payloads.

Expected outcome: Calling RequestLookNow() logs the buffer status, then the character describes what changed and speaks its answer. Calling SilenceVisionUntilAsked() stops the character from reacting to new vision frames until RequestLookNow() is called again.

RequestLookNow() above builds a new ConvaiVisionTriggerRequest with no explicit UpdateId on every call, so calling it again after a dropped acknowledgement sends a distinct trigger, not a safe replay — each call gets its own generated ID. To make a retry idempotent, generate one UpdateId up front, pass it to the constructor, and reuse the same value across retries; the backend then replays the original acknowledgement for that ID instead of triggering again. See Vision scripting API for the constructor signature.

Next steps

Vision scripting APITroubleshoot visionCustom frame sources

Last updated

Was this helpful?