Search Unity

IConvertGameObjectToEntity Before GameObjectConversionSystem

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Jun 25, 2019.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    Just wondering if there is a way to run IConvertGameObjectToEntity.Convert() before GameObjectConversionSystem.OnUpdate()
     
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Don't really get the question. You can create and manually call GameObjectConversionSystem.Update() if you need it to happen earlier.

    Otherwise you can use
    GameObjectConversionUtility.ConvertScene()
    GameObjectConversionUtility.ConvertGameObjectHierarchy()
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    I don't get the question either. There's multiple GameObjectConversionSystem systems that run, with one of them being the one that calls the IConvertGameObjectToEntity. You can create your own systems too and even convert Unity components into custom entities if you want.
     
  5. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    ok let me try and explain.

    I have a subScene with a gameObject containing some a data on a MonoBehaviour implementing IConvertGameObjectToEntity. Let call it buildData.
    Screen Shot 2019-06-25 at 8.26.11 PM.png
    I also have a GameObjectConversionSystem that required buildData but when I press "Rebuild Entities Cache" the GameObjectConversionSystem executes before IConvertGameObjectToEntity.

    Or is there a better way of doing this
     
  6. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,709
    OK if I understood correctly Im going to write a GameObjectConversionSystem for my gameObject , setUp the dependancies and use subScenes to cache as a bonus. Here is my 1st attempt at a manual GameObjectConversionSystem. Let me know if this is GarBo code

    Code (CSharp):
    1.    
    2. //[UpdateAfter(typeof(XXXXXXXX))]
    3.     public class HexSphereCovertToEntities : GameObjectConversionSystem
    4.     {
    5.  
    6.         protected override void OnUpdate()
    7.         {
    8.  
    9.             GameObject go = GameObject.FindGameObjectWithTag("tagHexSphereBuildGameObject");
    10.             HexSphereBuildDataLiveLink data = go.GetComponent<HexSphereBuildDataLiveLink>();
    11.             WORLD_SIZE worldSize = data.worldSize;
    12.             int subdivisionsCount = data.subdivisionsCount;
    13.             int raduis = data.raduis;
    14.             int hexesCount = data.hexesCount;
    15.             int triangleCount = data.triangleCount;
    16.  
    17.             Entity e = GetPrimaryEntity(go);
    18.             EntityQuery eqBuildDataComp = this.DstEntityManager.CreateEntityQuery(ComponentType.ReadOnly<HexSphereBuildDataComponent>());
    19.  
    20.  
    21.             if (this.DstEntityManager.HasComponent<HexSphereBuildDataComponent>(e))
    22.             {
    23.                 Entities.With(eqBuildDataComp).ForEach<HexSphereBuildDataComponent>((ref HexSphereBuildDataComponent d) =>
    24.                 {
    25.                     d.worldSize = worldSize;
    26.                     d.subdivisionsCount = subdivisionsCount;
    27.                     d.raduis = raduis;
    28.                     d.hexesCount = hexesCount;
    29.                     d.triangleCount = triangleCount;
    30.                 });
    31.             }
    32.             else
    33.             {
    34.                 var hexSphereBuildSettingsData = new HexSphereBuildDataComponent
    35.                 {
    36.                     worldSize = worldSize,
    37.                     subdivisionsCount = subdivisionsCount,
    38.                     raduis = raduis,
    39.                     hexesCount = hexesCount,
    40.                     triangleCount = triangleCount
    41.                 };
    42.  
    43.                 this.DstEntityManager.AddComponentData(e, hexSphereBuildSettingsData);
    44.             }
    45.         }
    46.     }