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

Feedback Simplifying Access to Foreign Components

Discussion in 'Entity Component System' started by alexandre-fiset, Aug 14, 2019.

  1. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    714
    I've been playing around with DOTS for months now, and there is one thing that I think it could accomplish better.

    The scenario:
    • System A operates on any entity with Component A. There could be thousands of them.
    • System B operates on any entity with Component B. There could be thousands of them.
    • Each Component A must be paired with a specific Component B in order to operate properly.
      • For instance, I may need to know which Camera belongs to which Player
      • For instance, I may need to know which Sun belongs to which Planet
    With a dependency injection system, such as Zenject, I could inject a manager in one line of code that refers to an ordered list of all B components, and then easily pair them with A components using simple (int) indentifiers. I could say: This "Camera", with is (int) playerId of 1, belongs to Players[1]. Then do code.

    Easy peasy.

    I've been struggling a lot with accomplishing that easily in DOTS.
    • There's a way to get an array of UniqueSharedComponentData, but no way that I know of to define the order of that array.
    • There's GetSingleton that works well out of the box to get one foreign component, but unfortunately it immediately completes all job dependency on its type (on the main thread). Which is not ideal. And it only returns one component.
    What would be really great is to have one exemplified and optimized way of reading data from components that don't belong to the current system. I know it can be done, but how, when and where I am not so sure.

    Someone already explained it to me in this thread, but I still find it not trivial enough, especially if you (Unity) wants to move all coders to the DOTS thingy.

    So this is my feedback: It would be nice to make it easier (or more documented) to have access to foreign components in a System.
     
    Last edited: Aug 14, 2019