Search Unity

What's the most efficient way to handle the following situation?

Discussion in 'Entity Component System' started by PhilSA, May 13, 2018.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Here's my situation:
    • I have two entity types: A and B
    • Entity type B has its Position/Rotation components modified by several systems
    • I want Entity type A to be assigned an entity of type B and "follow" it with some interpolation
    • In the future, entity type A and B might have to belong to different worlds, so they can't just be merged into the same entity
    I'm very unsure about the best way to handle this. So far I was thinking about adding a "FollowEntity" component to entity type A. FollowEntity would just contain an "Entity" to follow. Then, a "FollowEntitySystem" would go through all entities of type A, find the entity referenced by the FollowEntity component, get the Position/Rotation components on that entity, and more or less copy them to type A's position and rotation components.

    The main issue is that I don't think it's possible to do a "GetComponentData<>(Entity)" from within a job. So I wouldn't be able to get the Position/Rotation of the entity to follow. Would I be forced to not do this in a job, or are there other clever ways to accomplish this?

    You could imagine entity type B as a rigidbody, and entity type A as a meshRenderer that follows a rigidbody with interpolation. My rigidbodies will be in a "Simulation" world, and my renderers will be in a "Presentation" world
     
    Last edited: May 13, 2018
  2. isbdnt

    isbdnt

    Joined:
    May 16, 2017
    Posts:
    35
    Actually you can do a "GetComponentData<>(Entity)" by "ComponentDataFromEntity<>(Entity)"
     
    PhilSA likes this.