Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Using RenderTargetSensor for own Sensor

Discussion in 'ML-Agents' started by GamerLordMat, Dec 16, 2022.

  1. GamerLordMat

    GamerLordMat

    Joined:
    Oct 10, 2019
    Posts:
    185
    hello all,

    I generate a and Texture2D and RenderTarget at Runtime/Awake and want to add it to a RenderTargetSensor, that I would like to generate dynamically too.

    So how to do it? The constructor of RenderTargetSensor seems weird andd doesnt show up in the inspector once created.

    Thank you in advance :)
     
  2. GamerLordMat

    GamerLordMat

    Joined:
    Oct 10, 2019
    Posts:
    185
    Ok, so I got it. My fail was that RenderTargetSensorCoponent was the class I needed to generate too. To be sure it works I set in the ExecutionOrder that my custom sensor class is invoked before the agent.
    Code (CSharp):
    1. sensor = new RenderTextureSensor(render, true, s, SensorCompressionType.None);
    2.         RenderTextureSensorComponent r = gameObject.AddComponent<RenderTextureSensorComponent>();
    3.         r.Grayscale = true;
    4.         r.RenderTexture = render;
    5.         r.CompressionType = SensorCompressionType.None;
    6.         r.SensorName = s;
    7.         r.ObservationStacks = 2;
     
    hughperkins likes this.
  3. GamerLordMat

    GamerLordMat

    Joined:
    Oct 10, 2019
    Posts:
    185
    Now I can use a CNN with my sensor :D. I suppose their is a more elegant way but it is not enough documented that I want to fidle with it.
     
    hughperkins likes this.