docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class OneHotGridSensor

    Grid-based sensor with one-hot observations.

    Inheritance
    object
    GridSensorBase
    OneHotGridSensor
    Implements
    ISensor
    IDisposable
    Inherited Members
    GridSensorBase.CompressionType
    GridSensorBase.DetectableTags
    GridSensorBase.Reset()
    GridSensorBase.ResetPerceptionBuffer()
    GridSensorBase.GetName()
    GridSensorBase.GetCompressionSpec()
    GridSensorBase.GetBuiltInSensorType()
    GridSensorBase.GetCompressedObservation()
    GridSensorBase.Update()
    GridSensorBase.GetObservationSpec()
    GridSensorBase.Write(ObservationWriter)
    GridSensorBase.Dispose()
    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 OneHotGridSensor : GridSensorBase, ISensor, IDisposable

    Constructors

    OneHotGridSensor(string, Vector3, Vector3Int, string[], SensorCompressionType)

    Create a OneHotGridSensor with the specified configuration.

    Declaration
    public OneHotGridSensor(string name, Vector3 cellScale, Vector3Int gridSize, string[] detectableTags, SensorCompressionType compression)
    Parameters
    Type Name Description
    string name

    The sensor name

    Vector3 cellScale

    The scale of each cell in the grid

    Vector3Int gridSize

    Number of cells on each side of the grid

    string[] detectableTags

    Tags to be detected by the sensor

    SensorCompressionType compression

    Compression type

    Methods

    GetCellObservationSize()

    Get the observation size for each cell. This will be the size of dataBuffer for GetObjectData(GameObject, int, float[]). If overriding GetObjectData(GameObject, int, float[]), override this method as well to the custom observation size.

    Declaration
    protected override int GetCellObservationSize()
    Returns
    Type Description
    int

    The observation size of each cell.

    Overrides
    GridSensorBase.GetCellObservationSize()

    GetObjectData(GameObject, int, float[])

    Get the one-hot representation of the detected game object's tag.

    Declaration
    protected override void GetObjectData(GameObject detectedObject, int tagIndex, float[] dataBuffer)
    Parameters
    Type Name Description
    GameObject detectedObject

    The game object that was detected within a certain cell

    int tagIndex

    The index of the detectedObject's tag in the DetectableObjects list

    float[] dataBuffer

    The buffer to write the observation values. The buffer size is configured by GetCellObservationSize().

    Overrides
    GridSensorBase.GetObjectData(GameObject, int, float[])

    GetProcessCollidersMethod()

    Whether to process all detected colliders in a cell. Default to false and only use the one closest to the agent. If overriding GetObjectData(GameObject, int, float[]), consider override this method when needed.

    Declaration
    protected override ProcessCollidersMethod GetProcessCollidersMethod()
    Returns
    Type Description
    ProcessCollidersMethod

    Bool value indicating whether to process all detected colliders in a cell.

    Overrides
    GridSensorBase.GetProcessCollidersMethod()

    IsDataNormalized()

    Whether the data is normalized within [0, 1]. The sensor can only use PNG compression if the data is normailzed. If overriding GetObjectData(GameObject, int, float[]), override this method as well according to the custom observation values.

    Declaration
    protected override bool IsDataNormalized()
    Returns
    Type Description
    bool

    Bool value indicating whether data is normalized.

    Overrides
    GridSensorBase.IsDataNormalized()

    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)