Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved Using RenderTargetSensor for own Sensor

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

  1. GamerLordMat

    GamerLordMat

    Joined:
    Oct 10, 2019
    Posts:
    126
    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:
    126
    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:
    126
    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.