Search Unity

Why use GameObjectConversionSystem over IConvertGameObjectToEntity

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Sep 15, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Wondering if someone could explain to me why I would ever use GameObjectConversionSystem over IConvertGameObjectToEntity. It feel like if the general pattern is to use GameObject to author entities it should be very explicit by implementing the IConvertGameObjectToEntity.

    Thanks in advance
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    GameObjectConversionSystem vs IConvertGameObjectToEntity is similar to IJobChunk vs IJobForEach.

    GameObjectConversionSystem gives you the ability to take into account combinations of authoring components and exclusions of components as well as Unity built-in components. [RequiresEntityConversion] is how you can explicitly declare a component as an authoring component even if it isn't an IConvertGameObjectToEntity.
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Thanks for the reply. I’m still not 100% clear , what do you mean by combination, exclusion and build in. Do you have a code example I can compare. Is it the fact that it runs after IConvertGameObject giving you a hook to all entity data for further processing ?
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    Combination and Exclusion, you get to write Entities.ForEach and can create a custom query of GameObject components. For example, if I got a character component on a GameObject but no AI or or PlayerControl components, I might want to add a simple ECS component that loops the idle animation.

    As for built-in, I am writing a custom physics solution and being able to convert PhysX colliders into my custom data representations is awesome and something I couldn't do nearly as easily without GameObjectConversionSystem. Additional hook points are also really nice.
     
  5. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Got it , thanks for the explanation