docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class CameraSensor

    A sensor that wraps a Camera object to generate visual observations for an agent.

    Inheritance
    object
    CameraSensor
    Implements
    ISensor
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.MLAgents.Sensors
    Assembly: Unity.ML-Agents.dll
    Syntax
    public class CameraSensor : ISensor, IDisposable

    Constructors

    CameraSensor(Camera, int, int, bool, string, SensorCompressionType, ObservationType)

    Creates and returns the camera sensor.

    Declaration
    public CameraSensor(Camera camera, int width, int height, bool grayscale, string name, SensorCompressionType compression, ObservationType observationType = ObservationType.Default)
    Parameters
    Type Name Description
    Camera camera

    Camera object to capture images from.

    int width

    The width of the generated visual observation.

    int height

    The height of the generated visual observation.

    bool grayscale

    Whether to convert the generated image to grayscale or keep color.

    string name

    The name of the camera sensor.

    SensorCompressionType compression

    The compression to apply to the generated image.

    ObservationType observationType

    The type of observation.

    Properties

    Camera

    The Camera used for rendering the sensor observations.

    Declaration
    public Camera Camera { get; set; }
    Property Value
    Type Description
    Camera

    CompressionType

    The compression type used by the sensor.

    Declaration
    public SensorCompressionType CompressionType { get; set; }
    Property Value
    Type Description
    SensorCompressionType

    Methods

    Dispose()

    Clean up the owned Texture2D.

    Declaration
    public void Dispose()

    GetBuiltInSensorType()

    Return the corresponding BuiltInSensorType for the sensor.

    Declaration
    public BuiltInSensorType GetBuiltInSensorType()
    Returns
    Type Description
    BuiltInSensorType

    A BuiltInSensorType corresponding to the sensor.

    GetCompressedObservation()

    Generates a compressed image. This can be valuable in speeding-up training.

    Declaration
    public byte[] GetCompressedObservation()
    Returns
    Type Description
    byte[]

    Compressed image.

    GetCompressionSpec()

    Return information on the compression type being used. If no compression is used, return Default().

    Declaration
    public CompressionSpec GetCompressionSpec()
    Returns
    Type Description
    CompressionSpec

    An object describing the compression used by the sensor.

    GetName()

    Accessor for the name of the sensor.

    Declaration
    public string GetName()
    Returns
    Type Description
    string

    Sensor name.

    GetObservationSpec()

    Returns a description of the observations that will be generated by the sensor. The shape will be h x w x 1 for grayscale and h x w x 3 for color. The dimensions have translational equivariance along width and height, and no property along the channels dimension.

    Declaration
    public ObservationSpec GetObservationSpec()
    Returns
    Type Description
    ObservationSpec

    ObservationToTexture(Camera, Texture2D, int, int)

    Renders a Camera instance to a 2D texture at the corresponding resolution.

    Declaration
    public static void ObservationToTexture(Camera obsCamera, Texture2D texture2D, int width, int height)
    Parameters
    Type Name Description
    Camera obsCamera

    Camera.

    Texture2D texture2D

    Texture2D to render to.

    int width

    Width of resulting 2D texture.

    int height

    Height of resulting 2D texture.

    Reset()

    Resets the internal state of the sensor. This is called at the end of an Agent's episode. Most implementations can leave this empty.

    Declaration
    public void Reset()

    Update()

    Update any internal state of the sensor. This is called once per each agent step.

    Declaration
    public void Update()

    Write(ObservationWriter)

    Writes out the generated, uncompressed image to the provided ObservationWriter.

    Declaration
    public int Write(ObservationWriter writer)
    Parameters
    Type Name Description
    ObservationWriter writer

    Where the observation is written to.

    Returns
    Type Description
    int

    Implements

    ISensor
    IDisposable

    Extension Methods

    SensorExtensions.ObservationSize(ISensor)
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)