Access RayPerceptionSensor Components

I use the Ray Perception Component similar to the Pyramid example, but with curriculum learning.
I would now like to use the length of the ray as curriculum parameter.
How can I access the component in code?

Access it the same way you do any component. Something like..

using MLAgents.Sensor;

//your code here..

RayPerceptionSensorComponent3D sensor = targetTransform.GetComponent<RayPerceptionSensorComponent3D>();
sensor.rayLength = curriculumSetParameter;
1 Like

Thank you. I’ll implement it later.

That code probably won't work the way that you expect - the sensor implementation only gets the value from the component in its constructor (https://github.com/Unity-Technologies/ml-agents/blob/0f4368852920d8559af793273a2dd3e80a556e9e/UnitySDK/Assets/ML-Agents/Scripts/Sensor/RayPerceptionSensor.cs#L80) and this value is private so there's no accessor to change it.

I'm not sure there's any good way to do this right now. We're refactoring some of these interfaces, so let me get back to you.

Oh, that is unfortunate. Thank you for the notice.
Could it work with the deprecated RayPerception? In MLA Toolkit 0.12.1 it is still used in the pyramid scene. Please keep me up to date.

Sorry for the delay. Yes, it should work the deprecated RayPerception code.

I think I have a solution that will work for this; it should be in the next release. Note that some parameters (number of tags, number of rays, and number of stacked observations) can't be changed since they change the observation size, but everything else should be "tweakable" - see the gif in https://github.com/Unity-Technologies/ml-agents/pull/3484#issuecomment-590019491