Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Send an Output Event on Particle Death

Discussion in 'Visual Effect Graph' started by Hyralys, Mar 13, 2023.

  1. Hyralys

    Hyralys

    Joined:
    Mar 12, 2020
    Posts:
    2
    Hello,

    I have a VFX Graph that basically throw a particle with a certain velocity, and I want to send an event to a C# script when this particle dies by colliding with an object.

    So I used the Collide with Sphere node that makes the particle lose its lifetime on collision, which works great, but I wanted to know if there's a way to link an Event on die with an Output Event, or maybe is there another solution to get the same result ?

    Thanks VFXScreen.png
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,296
    This is currently not possible.
     
  3. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    183
    As said @Qriva this is not possible. "Output Event" are handled by the CPU while "GPU Events", well... it's in their name.
    With this being said, you can do some workaround to depending on your use case.

    -In the "Spawn Context" of your Parent system, you can set a "Spawn Event Lifetime".
    upload_2023-3-14_9-32-39.png

    -In the "initialize Context", use an "Inherit Source Lifetime". This way, your particle lifetime values will be set thanks to the values that you previously set in the "Spawn Event Lifetime".

    -From your parent "Spawn event" link a new "Spawn Event Context" with a single burst. By default, this new Spawn will be fire as soon as the parent, but you can add "a delay". This delay will be the "lifetime of your Parent particle".

    -Now, from this newly chained Spawn Context, you can wire an "Output Event". Setup this way, the Output Event will be fired with a delay corresponding to the "lifetime" of your Particle. This Output event is triggered when the particle dies.

    But in your case, you want to die on collision. So what you can do instead of using "Velocities" to drive your particle movement is to use its lifetime and Basic Lerp operation.

    I've been doing this for this VFX and it worked great. I'm lerping from the (0,0,0) local space of the VFXGraph to an exposed "Target Sphere" properties. To interpolate between the two position, I'm just using the "Age over lifetime" operator. This way, I know that my particle will be at the Sphere center when its lifetime reach 1.0.

    Et voilà. You can get really creative with your lerp operations and even add some rotation along the path.
    upload_2023-3-14_9-53-47.png

    The result is this:
    One System "Head Projectile" is spawn, this particle lerp from VFXG position to my Target over its lifetime.
    With Trigger Events and "GPU event" in the "Update Context", this particle is spawning a trail along the way.
    With Trigger Event and "Gpu event" on Die it Trigger a bunch of Other Systems.
    The Output Event is used on the "Target Sphere" to Animated its material.
    upload_2023-3-14_9-57-54.png vlc_nBJPhHkS08.gif

    Note that it's a workaround. It's not perfect and has a lot of limitations. But you can still achieve very nice effect and Send your Output Event. Hope this was helpful. Have a great day.
     
    Qriva likes this.