Search Unity

Bug Cannot have more then one IConvertGameObjectToEntity component on an object.

Discussion in 'Entity Component System' started by hoesterey, Dec 23, 2020.

  1. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Hi,
    Ran into an issue where the convert is not running on all my components.

    I have two authoring components on one game object that create the following:

    ProjectileSpawnerAuthoring -> dstManager.AddComponentData(entity, new ProjectileSpawner
    ProjectileSpawnerParamsAuthoring -> dstManager.AddComponentData(entity, new ProjectileSpawnerParams

    When the game is run my entity does not have a "Projectile Spawner Params" runtime component and will not pass filters.

    HOWEVER if I copy the code from ProjectileSpawnerParamsAuthoring into ProjectileSpawnerAuthoring it works just fine.

    un-working code:

    Code (CSharp):
    1. public class ProjectileSpawnerParamsAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
    2.     {
    3.         public Transform m_SpawnPosition = null;
    4.  
    5.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    6.         {
    7.             var spawnPoint = this.m_SpawnPosition != null ? conversionSystem.GetPrimaryEntity(this.m_SpawnPosition.gameObject) : Entity.Null;
    8.             dstManager.AddComponentData(entity, new ProjectileSpawnerParams
    9.             {
    10.                 ProjectileOwner = conversionSystem.GetPrimaryEntity(gameObject),
    11.                 SpawnTranslation = dstManager.GetComponentData<Translation>(spawnPoint),
    12.                 SpawnRotation = dstManager.GetComponentData<Rotation>(spawnPoint),
    13.             });
    14.         }
    15.         public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
    16.         {
    17.             if (m_SpawnPosition.gameObject != null)
    18.                 referencedPrefabs.Add(m_SpawnPosition.gameObject);
    19.         }
    20.     }
    Copied code working just fine:

    Code (CSharp):
    1.  public class ProjectileSpawnerAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
    2.     {
    3.         public GameObject m_ProjectilePrefab = null;
    4.         public float m_Cooldown;
    5.         public Transform m_SpawnPosition = null;
    6.  
    7.         public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    8.         {
    9.             dstManager.AddComponentData(entity, new ProjectileSpawner
    10.             {
    11.                 m_Cooldown = this.m_Cooldown,
    12.                 m_ProjectilePrefab =  this.m_ProjectilePrefab != null ? conversionSystem.GetPrimaryEntity(this.m_ProjectilePrefab) : Entity.Null
    13.             });
    14.  
    15.             var spawnPoint = this.m_SpawnPosition != null ? conversionSystem.GetPrimaryEntity(this.m_SpawnPosition.gameObject) : Entity.Null;
    16.             dstManager.AddComponentData(entity, new ProjectileSpawnerParams
    17.             {
    18.                 ProjectileOwner = conversionSystem.GetPrimaryEntity(gameObject),
    19.                 SpawnTranslation = dstManager.GetComponentData<Translation>(spawnPoint),
    20.                 SpawnRotation = dstManager.GetComponentData<Rotation>(spawnPoint),
    21.             });
    22.         }
    23.         public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
    24.         {
    25.             if (m_ProjectilePrefab != null)
    26.                 referencedPrefabs.Add(m_ProjectilePrefab);
    27.             if (m_SpawnPosition.gameObject != null)
    28.                 referencedPrefabs.Add(m_SpawnPosition.gameObject);
    29.         }
    30.     }