Search Unity

Fast/Optimized way to push a position FROM a Transform TO an Entity's Position?

Discussion in 'Entity Component System' started by FrankvHoof, Mar 8, 2019.

  1. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    For a project I'm working on creating a custom hybrid system to perform a simple raycast-collision-detection.
    Due to the nature of the project I need to use the actual GameObjects.
    After looking at both a system with, and without using Entities (IJobs (incl parallel) vs IJobProcessComponentData), I found that creating Entities just for the system was actually the most performant way to do it.
    The system itself is fine, however, I'm stuck on 4 lines.
    Code (CSharp):
    1. foreach (KeyValuePair<MyPointObject, GameObject> item in x)
    2.             {
    3.                 Entity e = GetEntity(item.Key.ID);
    4.                 EntityManager.SetComponentData(e, new Position { Value = item.Value.transform.position });
    5.             }
    I need to get the position of the GameObject into the Position of its corresponding Entity before my Jobs can run. Because Transform is a class, I need to do this in the OnUpdate-Method (I think?). However, using EntityManager.SetComponentData, this is taking roughly 4.5 ms to process around 200 Objects.



    What would be a better/more performant way to handle this? (Especially considering I need access to the Transform-Class of the GameObjects?)
     
  2. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    have you tried adding
    CopyTransformFromGameObjectProxy

    This will syncronize the game object transform with the entity's position (now called translation, as of preview 26) component
     
    Last edited: Mar 8, 2019
  3. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Not yet.. Would you be able to provide some documentation as to how it's used? (Google doesn't seem helpful)
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,775
  5. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    After doing a test with an empty gameobject, it seems to not actually be updating the translation-component (proxy) on the gameobject. It should be doing this in one of Unity's built-in systems, no?
    https://gyazo.com/6f1b27f98d1ac62101fc80a4639739f1
     
  6. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    add a
    LocalToWorld
    proxy and you will see it update (sync). Translation only show changes not current position
     
    kro11 likes this.
  7. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    TheTranslationProxy still seems to be empty, even when adding the LtW (doesn't seem to show change/movement either, even when moving LARGE amounts)
    But hey, I can grab the position from the LocalToWorldProxy.Value, so thanks ;)
     
    kro11 likes this.