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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Stuck with ECS and reference ICompontentData

Discussion in 'Entity Component System' started by MrRobinOfficial, Jun 23, 2020.

  1. MrRobinOfficial

    MrRobinOfficial

    Joined:
    Jul 15, 2017
    Posts:
    13
    Hi, I'm currently working on a project with Unity ECS code. I have now come to a stop with some problem. The problem is that I need to get two different component data from different entity, however same root parent.

    For an example:

    WheelSystem -> ref WheelData wheel, in VehicleData vehicle

    Vehicle: (VehicleData ) (Entity)

    - Body (Entity)

    - Wheels (Entity)

    - FrontLeft:Wheel (WheelData ) (Entity)

    In Monobehavior answer would be GetComponentInChildren, right? So how does this work in ECS? I also tried of just linking Entity on IComponentData, which work. However if I Instance prefab with same data, I also need to re-link entity from the beginning. Is there more simpler way or smarter way?
     
  2. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    437
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,695
    Something it’s useful to create your game object as you usually would with collider children etc and then drag it into a sub scenes to see how it was converted , even a mock-up of what you want and dragging it into a sub scene can show child parents linked components etc.
     
  4. MrRobinOfficial

    MrRobinOfficial

    Joined:
    Jul 15, 2017
    Posts:
    13
    Last edited: Jun 23, 2020
  5. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    437
    It depends, you should avoid updating using a reference to other entity. For spinning, I would use separate system.
     
  6. MrRobinOfficial

    MrRobinOfficial

    Joined:
    Jul 15, 2017
    Posts:
    13
    Got it working, thanks. Little bit complicated, but it's working. My ideal with this game it would run around 50-200 vehicles at same time (traffic simulation), as well player vehicle. That's why I need to convert Monobehaviour into DOTS.