Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Add particle in DOTS

Discussion in 'Entity Component System' started by iamshenkui_gee, Jul 11, 2022.

  1. iamshenkui_gee

    iamshenkui_gee

    Joined:
    Apr 24, 2021
    Posts:
    30
    It seems that if I add a particle system directly to the prefabs. There will be some problems using DOTS. Such as it cannot be queried by the EntityQuery and the collision cannot be detected. So how can we use particle systems in DOTS?

    The unity game following error:
    ArgumentException: DestroyEntity(EntityQuery query) is destroying entity Entity(50:1) '' which contains a LinkedEntityGroup and the entity Entity(52:1) '' in that group is not included in the query. If you want to destroy entities using a query all linked entities must be contained in the query..
     
  2. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    262
    I think 'old Unity particles' and 'new Unity VFXgraph' particles should both be added as a ComponentObject.
    They will probably not work with the physics system. I only use VFX graph, which never worked with the physics system. So I am not sure about the 'old Unity particles'.
    VFXgraph is on the GPU so all physics data needs to be send to the GPU. There are some nodes that can collide with depth buffer, or with a plane. So you could do something, but its not out of the box.

    You can Query this data, but only WithoutBurst + .Run()

    Code (CSharp):
    1. Entities
    2.             .WithoutBurst()
    3.             .ForEach((VisualEffect vfx, in FollowingEntity toFollow) =>
    4.             {
    5.                // your code here
    6.                 }
    7.  
    8.             }).Run();
     
    bb8_1 likes this.
  3. iamshenkui_gee

    iamshenkui_gee

    Joined:
    Apr 24, 2021
    Posts:
    30
    Thank you for the reply. But I am still confused about it. How can we add two particle components as components?

    Or should I just regard the VFX as a normal game object, and Instantiate it from the command Buffer?
     
  4. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    262
    I don't have a deep knowledge, if it works its good enough for me.

    Some stuff you want does not work in DOTS. Animation, Audio, Particles, Terrain, Mixed lighting, who knows what else you will run into... anyway some of these can be mitigated by having a normal GameObject in the scene that follows an entity around. This is how I look at Component Objects. So you lose all of the DOTS benefits and in return you get the ability to make a game that includes sound, music and animation.

    Because Entities don't allow multiple of the same Components... I can imagine its not possible to add 2 Audio sources to a single Entity. If this is the case just use multiple entities.

    You can just convert a prefab to Entity prefab with a Converter script :
    Code (CSharp):
    1. public class AudioAndVFXConverter : MonoBehaviour, IConvertGameObjectToEntity
    2. {
    3.     public VisualEffect visualEffectCompanion;
    4.  
    5.     public AudioSource audioSourceCompanion;
    6.  
    7.     public AudioLowPassFilter lowPassCompanion;
    8.  
    9.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    10.     {
    11.         dstManager.AddComponentObject(entity, visualEffectCompanion);
    12.         dstManager.AddComponentObject(entity, audioSourceCompanion);
    13.  
    14.         //Debug.Log($"audioConversion lowPass = {lowPassCompanion != null}, {lowPassCompanion}");
    15.  
    16.         if (lowPassCompanion != null)
    17.         {
    18.             dstManager.AddComponentObject(entity, lowPassCompanion);
    19.         }
    20.     }
    21. }
    You can Instantiate this entity with the EntityManager or with the ECB and it will automagicly create the Entity, the companion link and the GameObject and keep these two at the same position (They won't show up in the editor unless you make this fix https://forum.unity.com/threads/hybrid-rigidbodies-in-editor-0-50.1272119/#post-8073257).

    It is a normal gameObject, but you can access and alter it from within a Entities.ForEach... I guess it saves some work form having your own GameObject-Entity relation checker.

    You get an Entity like this:
    upload_2022-7-13_9-57-57.png



    Where the Companion Link - GameObject is just a normal Game Object.

    upload_2022-7-13_10-0-1.png