Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why implement SensorComponent and ISensor in separate classes?

Discussion in 'ML-Agents' started by SSS135, May 27, 2020.

  1. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    65
    Hi, I have noticed that built-in sensors have different classes implementing SensorComponent and ISensor, like CameraSensorComponent and CameraSensor. I made my own sensors with only a single class inheriting from both SensorComponent and ISensor. It works fine, requires almost 2x less code and simpler to understand. Why standard sensors have two different classes?
     
  2. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    Hi @SSS135,
    The original motivation was to separate the editor-facing part (SensorComponent) from the runtime part (ISensor). ISensor has no dependency on MonoBehaviour, which in theory should make easier to make compatible with DOTS when we start on that.

    In retrospect, they might be a bit over-engineered, since as you mention, there's a lot of redundancy.

    Anyway, I'm glad that you're able to implement your own versions of them and get them working...

    -Chris