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

Workflow for Hybrid ECS

Discussion in 'Entity Component System' started by hobohak, Mar 21, 2020.

  1. hobohak

    hobohak

    Joined:
    Mar 2, 2020
    Posts:
    6
    Hey all,

    sorry for the longer post.

    I want to convert my Model (either as a gameobject on the scene or as a prefab) to an Entity holding all components.
    Afaik Unity offers three conversion workflows:
    1. SubScene (recommended by Unity)
    2. ConvertToEntity w/ option 'Convert and Destroy'
    3. ConvertToEntity w/ option 'Convert and Inject'
    For completeness I attached the workflows and added them at the end of the post.

    For pure ECS I can recommend the SubScene workflow.
    But since Animations and other unity components are not yet integrated in the conversion to ECS I need to stick to somewhat hybrid.
    The only valid approach I can see, is to use the 'Convert and Inject' method combined with the component 'Copy Transform to game object'.
    This generates an entity that updates the game object.
    This game object still has a valid Animator component. So it seems to work :)

    Now I have the following questions:
    • Is this the valid conversion workflow to achieve the desired result with the current release of unity?
      • If yes, why does it show an Error in the Inspector saying 'GameObjectEntity will have no effect[...]'.. even if its needed for the CopyTransform? (see attachment)
      • If yes, Are the components really splitted into the both generated parts (Entity and GameObject) or are they stored twice?
      • If no, what would be the correct approach :)
    I hope the problem is somewhat clear. Thanks in advance!

    cheers.


    1. Workflow: SubScene
    SubScene.png

    2. Workflow: Convert and Destroy

    ConvertAndDestroy.png
    3. Workflow: Convert and Inject
    ConvertAndInject.png

    Error Inspector
    InspectorError.JPG
     
    Last edited: Mar 21, 2020
    eatbuckshot likes this.
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    AFAIK GameObjectEntity and those CopyXXXProxy have been deprecated in the lastest versions. Also, now we have "HybridComponents" in the SubScene workflow, which allows us to have Animator (and other Mono stuff) in our entities.

    I really recommend you to read that: https://gametorrahod.com/game-object-conversion-and-subscene/

    It really helped me a lot to understand the current state of the Hybrid ECS.
     
    Havyx, PrimalCoder, lclemens and 3 others like this.
  3. hobohak

    hobohak

    Joined:
    Mar 2, 2020
    Posts:
    6
    So I studied the resource @brunocoimbra.

    I tried to use the subscene workflow and adding the particle and animator as a hybridcomponent.
    To accomplish that you would create the necessary compagnions.
    During the Convert method you can add them. See code below.

    It throws no error and particles are shown.

    The Animator though is not applied with a compagnion link and therefore does not play.

    So I think this currently does not work and is currently still in development (as the wholesubscene workflow is I guess).
    I will stick with Convert & Inject workflow until then with the adjustments recommended in the resources in the link provided by @brunocoimbra
    !! Thank you for providing this link. It really helps a lot (though sometimes hard to read) and I highly recommend it !!

    If anyone has a different thought on implementing Animator,please give some insights.


    Thanks & cheers !

    Code (CSharp):
    1.  
    2. public class HeroSubScene : MonoBehaviour, IConvertGameObjectToEntity
    3. {
    4.     public float SomeTestValue = 5f;
    5.     public ParticleSystem particleCompagnion;
    6.     public ParticleSystemRenderer rendererCompagnion;
    7.     public Animator animationCompagnion;
    8.  
    9.  
    10.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    11.     {
    12.         var heroTag = new HeroTag() { SomeTestValue = SomeTestValue };
    13.         dstManager.AddComponentData(entity, heroTag);
    14.      
    15.         //Add compagnions.
    16.         conversionSystem.AddHybridComponent(particleCompagnion);
    17.         conversionSystem.AddHybridComponent(rendererCompagnion);
    18.         conversionSystem.AddHybridComponent(animationCompagnion);
    19.     }
    20. }
    21.  
     
    PadBack and brunocoimbra like this.