How to get RayPerceptionSensor values

Hi everyone, I would like to recover the values of the “RayPerceptionSensor” how can I do?
Moreover I know that the observations of the RayPerceptionSensor are directly added to the observations, is it possible that this is not the case?

You can recover the values by using method: Perceive in Class RayPerceptionSensor.
You will need the GetRayPerceptionInput() from Class RayPerceptionSensorComponentBase

The observation are added in the file com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
So I see two options

  1. implement your own sensor using the ISensor interface
  2. that’s kind of a long shot, but maybe put sensor in the child of the game object in which the agent script is, and tag “use child sensors” off. Then the agent wont use sensor, but you will be able to access it using Perceive
    (Never tried either, but I think it’s worth a shot)
1 Like

Use @ShirelJosef 's answer, I was able to access sensor output in Unity C# with the following code:

var c = GetComponent<RayPerceptionSensorComponent3D>();
RayPerceptionInput spec = c.GetRayPerceptionInput();
RayPerceptionOutput obs = RayPerceptionSensor.Perceive(spec);

And then use the data contained in RayPerceptionOutput obs documented here: [Class RayPerceptionOutput | ML Agents | 1.0.8

H](Class RayPerceptionOutput | ML Agents | 1.0.8)owever, I don’t know if observations can be prevented from automatically being appended, as @Twyy_Ztn asked earlier.