Search Unity

Access RayPerceptionSensor Components

Discussion in 'ML-Agents' started by Twyth, Feb 6, 2020.

  1. Twyth

    Twyth

    Joined:
    Apr 27, 2017
    Posts:
    7
    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?
     
  2. Satyros

    Satyros

    Joined:
    Feb 8, 2015
    Posts:
    6
    Access it the same way you do any component. Something like..

    Code (CSharp):
    1.  
    2. using MLAgents.Sensor;
    3.  
    4. //your code here..
    5.  
    6. RayPerceptionSensorComponent3D sensor = targetTransform.GetComponent<RayPerceptionSensorComponent3D>();
    7. sensor.rayLength = curriculumSetParameter;
    8.  
    9.  
     
    Twyth likes this.
  3. Twyth

    Twyth

    Joined:
    Apr 27, 2017
    Posts:
    7
    Thank you. I'll implement it later.
     
  4. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    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-Technologi...nts/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.
     
  5. Twyth

    Twyth

    Joined:
    Apr 27, 2017
    Posts:
    7
    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.
     
  6. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    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