docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class BufferSensor

    A Sensor that allows to observe a variable number of entities.

    Inheritance
    object
    BufferSensor
    Implements
    ISensor
    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 BufferSensor : ISensor

    Constructors

    BufferSensor(int, int, string)

    Creates the BufferSensor.

    Declaration
    public BufferSensor(int maxNumberObs, int obsSize, string name)
    Parameters
    Type Name Description
    int maxNumberObs

    The maximum number of observations to be appended to this BufferSensor.

    int obsSize

    The size of each observation appended to the BufferSensor.

    string name

    The name of the sensor.

    Methods

    AppendObservation(float[])

    Appends an observation to the buffer. If the buffer is full (maximum number of observation is reached) the observation will be ignored. the length of the provided observation array must be equal to the observation size of the buffer sensor.

    Declaration
    public void AppendObservation(float[] obs)
    Parameters
    Type Name Description
    float[] obs

    The float array observation

    GetBuiltInSensorType()

    Return the corresponding BuiltInSensorType for the sensor.

    Declaration
    public BuiltInSensorType GetBuiltInSensorType()
    Returns
    Type Description
    BuiltInSensorType

    A BuiltInSensorType corresponding to the sensor.

    GetCompressedObservation()

    Return a compressed representation of the observation. For small observations, this should generally not be implemented. However, compressing large observations (such as visual results) can significantly improve model training time.

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

    Compressed observation.

    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()

    Get the name of the sensor. This is used to ensure deterministic sorting of the sensors on an Agent, so the naming must be consistent across all sensors and agents.

    Declaration
    public string GetName()
    Returns
    Type Description
    string

    The name of the sensor.

    GetObservationSpec()

    Returns a description of the observations that will be generated by the sensor. See ObservationSpec for more details, and helper methods to create one.

    Declaration
    public ObservationSpec GetObservationSpec()
    Returns
    Type Description
    ObservationSpec

    An object describing the observation.

    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)

    Write the observation data directly to the ObservationWriter. Note that this (and GetCompressedObservation()) may be called multiple times per agent step, so should not mutate any internal state.

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

    Where the observations will be written to.

    Returns
    Type Description
    int

    The number of elements written.

    Implements

    ISensor

    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)