Search Unity

ComponentDataProxy in ConvertToEntity hierarchies

Discussion in 'Entity Component System' started by florianhanke, Sep 11, 2019.

  1. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Hi all,

    I have a GizmoSystem that will render useful information of all entities that are tagged with the Gizmo component when the GizmoSystem queries match.

    It's very simple:

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. namespace BUD.Components
    4. {
    5.     public struct Gizmo : IComponentData { }
    6.  
    7.     public class GizmoComponent : ComponentDataProxy<Gizmo> { };
    8. }
    ComponentDataProxy seems to depend on the GameObjectEntity component, which is slightly annoying here – whenever I add a GizmoComponent on a child entity in a ConvertToEntity hierarchy, I see the following warning pop up, rightly so:

    Screenshot 2019-09-11 11.12.19.png

    It's pretty distracting. Could the dependency of ComponentDataProxy on GameObjectEntity be removed?

    Thanks in advance and have a great day!
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Your GizmoComponent should be MonoBehaviour and implementing IConvertGameObjectToEntity for working with ConvertToEntity.
    Code (CSharp):
    1. [DisallowMultipleComponent]
    2. public class FogOfWarAffectorProxy : MonoBehaviour, IConvertGameObjectToEntity
    3. {
    4.     public int AffectRadius = 10;
    5.    
    6.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    7.     {
    8.         dstManager.AddComponentData(entity, new FogOfWarAffector { AffectRadius = AffectRadius });
    9.     }
    10. }
     
  3. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Thanks, @eizenhorn!

    I went with your solution:

    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3.  
    4. namespace BUD.Components
    5. {
    6.     public struct Gizmo : IComponentData { }
    7.  
    8.     namespace Authoring
    9.     {
    10.         public class GizmoComponent : MonoBehaviour, IConvertGameObjectToEntity
    11.         {
    12.             public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    13.             {
    14.                 dstManager.AddComponent(entity, typeof(Gizmo));
    15.             }
    16.         }
    17.     }
    18. }
    19.