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 Kill particle with custom form or object ?

Discussion in 'Visual Effect Graph' started by Maxoumi, Sep 2, 2022.

  1. Maxoumi

    Maxoumi

    Joined:
    Nov 12, 2020
    Posts:
    14
    Good morning !

    I currently use a particle system where I need to be able to delete certain particles at specific locations with predefined objects or forms!

    There are currently only Kill Sphere and AABox to destroy particles which might not be enough.

    The best would be to be able to define a mesh, a collider in the VFX graph or directly in the scene with a gameObject, I don't care. Basically I would like all the particles that are in this form to be removed.

    I looked everywhere there is not really any information on this subject and normal there is little use of particle like mine I suppose.

    Thank you in advance for your help !

    PS: Sorry for my bad English it's not my native language
     
  2. Maxoumi

    Maxoumi

    Joined:
    Nov 12, 2020
    Posts:
    14
    Nobody ?
     
  3. XieJiJun

    XieJiJun

    Unity Technologies

    Joined:
    Apr 8, 2022
    Posts:
    3
    Collide with SDF and let the Lifetime Loss to 1.
     
    Qriva likes this.
  4. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @Maxoumi ,

    As @XieJiJun suggested, you can add a Collide with Signed Distance Field block in your Update context and set the Lifetime Loss value to 1 (meaning particles will lose their full life if they collide with the SDF).


    We added a built-in SDF baker in 2021.2 which you can access via Window > Visual Effects > Utilities > SDF Baker.
    You can find a bit more info on how to use it in this video (starts around 19:32).

    Once you've baked your shape, you can position it with the Field Transform value of this block.

    Hope this helps!
     

    Attached Files:

    XieJiJun and OrsonFavrel like this.
  5. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    Morning, as stated above if you need "precise" collision, SDF (Signed Distance Field) could be a good fit for what you're looking for.
    To simplify, "sampling" the SDF of a Mesh with your "Particle Position" will return the distance to the Closest Surface.
    This distance value can either be "Positive" or "Negative" (signed) if the sample postion is Inside the Outside of the Surface. And a value of 0 would be mean that the Particle is actually on the Surface.

    So with this, you can either use the "Sample Distance Field" Block operator , or directly use the "Collide with SDF" Block context.
    upload_2022-9-8_10-2-13.png upload_2022-9-8_10-2-26.png

    Both of them would need you to provide an SDF as Input to know Which SDF to sample.
    And you will also need to provide a "Transform" of the Mesh you want you're particles to Collide with.

    So the Steps would be:

    1. Create a "3dtexture" exposed property
    2. Create a "Transform" exposed property and set it to "WorldSpace".
    upload_2022-9-8_10-8-31.png
    3. Create and Collide with "SDF" in the "update Context".
    4. Wire the Distance Field, and Transform Properties.
    5. Set the Lifetime Loss to 1 ( Particles will Lose 100% of their Lifetime when colliding with the Shape)
    6. Make sure the Mode is set to "Solid"
     

    Attached Files:

    XieJiJun and VladVNeykov like this.
  6. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    upload_2022-9-8_10-11-21.png

    7. You need to Bake the "Mesh" to an SDF (will be store in a 3d texture."
    8. Window> Visual Effect >Utilities > SDF Bake Tool
    upload_2022-9-8_10-14-20.png
    8. Bake your Mesh and Save the SDF as a 3d Texture.
    upload_2022-9-8_10-15-10.png

    9.In the Scene, select your VFX and set your SDF properties
    upload_2022-9-8_10-16-36.png

    10. Add a VFX Property Binder to your VFX object.
    11. In this VFX property Component , add a Transform Binding.
    12. Select the Target (the Mesh in the Scene you want to get the "Transform" from.
    13. Select your 3d Texture property.
     

    Attached Files:

    henners999 likes this.
  7. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    And you should be good to go...
     

    Attached Files:

  8. Maxoumi

    Maxoumi

    Joined:
    Nov 12, 2020
    Posts:
    14
    Thank you very much for your response! That worked perfectly!
     
    Last edited: Sep 13, 2022
    OrsonFavrel likes this.