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

What's currently the best way to do hybrid ECS?

Discussion in 'Entity Component System' started by Deleted User, Jul 11, 2019.

  1. Deleted User

    Deleted User

    Guest

    There are other threads about this, but ECS workflows are changing really quickly.
    I want to know what is the way to do hybrid ECS now?
     
  2. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    The conversion workflow is the most update to date hybrid workflow.
     
  3. Deleted User

    Deleted User

    Guest

    Can you tell me a little bit about it?

    AFAIK conversion workflow is an editing workflow for things that can be converted to entities.

    What I want to know is that what is the workflow for things that cannot be converted to entities. Like audio, or UI, or animations.
     
  4. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    Well, for things like audio/animations, can you certainly grab the components as the components attached to the game object will certainly defined as an archetype.

    So if you had a gameObject with a ConvertToEntity with ConvertAndInjectOriginal conversion mode, you can see that a gameObject that has been converted will have the Unity Components as an archetype.

    upload_2019-7-11_14-40-52.png

    Meaning that you can reference these Unity Components via ComponentSystem using their Fluent API

    Entities.With(some_query).ForEach((Animator anim) => {});


    For UI, the ConvertToEntity may not work well with Unity's UI (might be an issue with trying to convert a RectTransform instead of a regular gameObject transform which may not be handled yet).

    You can create your own conversion to handle the rect transform; which I remember reading 5argon's blog about GameObjectConversions but looks like that blog post is down. Similarly, there is a community effort for a DOTs based UI which I'll link to afterwards after I find the thread.

    Edit: here's the pure dots UI implementation: https://forum.unity.com/threads/sho...led-description-feedback.688531/#post-4605706
     
  5. Deleted User

    Deleted User

    Guest

    I tried it. It seems like it creates two objects. One gameobject and one entity. right?

    I tried it with CharacterController. When I moved the CharacterController with a system, Only the gameobject CharacterController started to move. Is this expected behavior or bug?
     
  6. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    I don't understand what you mean, you tried the ConvertToEntity and it created another object? ConvertToEntity doesn't create another object, it can either destroy or keep the existing gameObject. Regardless of which conversion mode you select, an entity is constructed with the components associated with the entity. Also I don't get the context of the situation you're describing.
     
  7. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,222
    ConvertToEntity with injecting the GameObject will cause some of the built-in components to get both GameObject and ECS representations (since there exist conversion systems which always add the ECS components but don't destroy the old components). This especially applies to MeshRenderers and confuses a lot of people. When doing Convert and Inject, you have to decide which set of components you want to use and destroy/ignore the others.

    The two transform systems do not automatically sync.
     
    Resshin27 and psuong like this.
  8. Deleted User

    Deleted User

    Guest

    I have this gameobject in editor:

    upload_2019-7-12_9-25-17.png

    I have a system that moves every CharacterController in the scene. When I play, the result I get is this:

    upload_2019-7-12_9-26-20.png

    So on every game object that I want to convert, I should attach an script that destroys duplicate components?
     
  9. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    126
    With the injected gameObject, yes. Adding a simple RemoveComponent<MeshRenderer> in an IGameObjectToEntity interface implementation might be the simpler option here. I'm also wondering if you'll need the MeshFilter too. As for ensuring the transform gets updated from gameObject -> entity, you'll want to add CopyTransfromFromGameObject if you want to solely use the LocalToWorldMatrix to compute transforms instead of using the GameObject's Transform.

    View attachment 449267
     

    Attached Files:

  10. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,222
    I'm currently working on a custom ConvertToEntity script that will transform an entire hierarchy with injected GameObjects using a single conversion world. It will also go through and post-process to remove all the duplicate components. I'm mostly doing this to remove some startup lag for the 10% of things that are stuck in GameObject land and to remove some runtime overhead, but I'm sure it is also really useful for those looking to do an aggressively hybrid approach.
     
    Deleted User and psuong like this.