Search Unity

Is it still possible/recommended to copy translation values back to GameObject?

Discussion in 'Entity Component System' started by Reshima, May 30, 2019.

  1. Reshima

    Reshima

    Joined:
    Dec 10, 2012
    Posts:
    51
    I've played with ECS before and at that time I remember there was a Pure vs Hybrid approach. I see now in the docs that there's no mention to hybrid anymore (probably to avoid the confusion it was creating?). I tried to find any announcements about it and I couldn't find.

    My question is: can I still copy the translation values from entity back to gameobject?

    Here's my setup:

    - GameObjectA with
    ConvertToEntity
    set to "Convert and Inject Game Object".
    - GameObjectA with
    MoveSpeedAuthoring
    which is the monobehavior that implements
    IConvertGameObjectToEntity
    to convert game object value to entity value.
    -
    MovementSystem
    which just sets a new translation value based on the movespeed and delta time.

    Everything works from entity side, except I want to update the game object values to match the entity translation value. How can I do it?

    I remember there was a
    Copy Transform to GameObject
    script but since I don't see those in the docs anymore I'm assuming it's being deprecated (it also complains if used with
    Convert to Entity
    )

    So how can I keep my code hybrid for now but using ECS under the hood? (Reason is: I still want to use the old physics system as I want to wait for the new one to mature in performance, and I'm doing a 2D game which sprite renderer is not a first-class citizen yet for the hybrid renderer).
     
  2. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    169
    Treat yourself :)

    Code (CSharp):
    1.  
    2. public class CopyTransformToGameObjectComponent: MonoBehaviour, IConvertGameObjectToEntity
    3.     {
    4.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    5.         {
    6.             dstManager.AddComponent(entity, typeof(CopyTransformToGameObject));
    7.         }
    8.     }
    9.  
     
    nantoaqui and Reshima like this.
  3. Reshima

    Reshima

    Joined:
    Dec 10, 2012
    Posts:
    51
    Great! Thanks a lot!