planetarium/UniLibplanet

Remove `MonoBehaviour` from `Agent` or implement a better support

Opened this issue · 0 comments

Current implementation of Agent inherits from MonoBehaviour of the Unity engine library. From what I have gathered, including a casual comment from @boscohyun, there doesn't seem to be an explicit reason for such inheritance. 😶

The purpose of using MonoBehaviour is to integrate with Unity's handling of a script's lifecycle. To be blunt, the current state seems like a half-baked attempt at doing so, and does not seem to provide a tangible benefit, other than possibly providing automatic disposal of Swarm<T> through OnDestroy().

As IEnumerable<IRenderer<T>> must be passed on to Agent initialization, this heavily influences the structure of Unity game scripts. The overhead of knowing and properly managing an Agent object is already substantial, and I don't think there is enough benefit to having automatic Swarm<T> disposal to grant having implicitly hidden partial lifecycle management for Agent. 🙄

Although there is a possible issue of calling UI updating portion of the code with Agent.RunOnMainThread(), but conceptually, I think it makes better sense to have this on the client's game script side rather than as a part of Agent.