Search Unity

Entity Particle System

Discussion in 'Entity Component System' started by shotoutgames, Jan 16, 2020.

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    What method if any to add a Particle System Game Object to an Entity Bullet.
    Previously when using Game Objects I would just make the Particle System a child of the moving bullet to add a particle effect.
    I have been experimenting but without success.
    Thanks
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Code (CSharp):
    1. entityManager.AddComponentObject(entity, particleSystem);
    2. entityManager.AddComponentData(entity, new CopyTransformToGameObject { });
     
  3. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    I am pretty newbie so not sure how to implement this.
    I was using IConvertGameObjectToEntity and it wont add the particle system to my prefab bullet entity.
    I can add it to a bullet in the scene but I need the particle to be in sync with the entity positions for all instances as they travel.
     
  4. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    the way i see it:

    1) spawning Projectiles Entities with EffectID CD.

    2) a LinkPrefabsSystem (ComponentSystem) tracks all entities with EffectID but without EffectIDSystemState and get the required Prefab from pool otherwise instantiate a new one.

    the correct way to link a transform to an Entity, (make sure your entity has the LocalToWorld cd)
    Code (CSharp):
    1.  
    2. GameObject BulletPrefab; // a normal gameObject from Pool
    3. entityManager.AddComponentObject(ProjectileEntity, BulletPrefab.transform);
    4. entityManager.AddComponentData(ProjectileEntity, new CopyTransformToGameObject { });
    5.  
    3) the ProjectileEntity do it's job and get destroyed.

    4) a RecyclePrefabsSystem (ComponentSystem) tracks all entities with EffectIDSystemState but without EffectID,
    * recycle the prefab used,
    * removes the EffectIDSystemState
    * destroyes the ProjectileEntity .