Kill strip particle when "head" particle dies?

I’m new to VFX graph generally, and I’m trying to kill a strip when it’s “head” particle dies.

atm the particle lingers after the main particle is killed.

I guess that you’re talking about a classical scenario of Spawning a trail/strip thanks to GPU Events?
If so, this will depends on how your head is dying.

If the cause is natural death:
:skull:= Age >= Lifetime ? 0 : 1;
then you’re in luck.

For this, you can inherit the Lifetime and Age of your Head particles.
If you create a new VFX you can take a look at the Head and Trail template that is set up this way.
Unity_p9UkcDipxz

Now, if the cause of :skull_and_crossbones: isn’t natural, some workaround would be needed as if I’m correct, no relation is kept between the Child and their parent when using GPU Events.

Now, They’re multiple ways of spawning Trail/strip (While still having a head) that don’t require GPU Events. This might be a side track, but if you’re interested, I would suggest that you take a look at the VFX Learning Sample as it contains some examples on how to spawn Strips with or without GPU-events.

yeah it’s the second case, in short I want the strips to be killed on collison but they seem to just stop instead.

The only decent solution so far is a short lifetime so it’s not too noticeable.

So if they are not dying due to their lifetime, you need to use work around.
A solution that can work is to use a buffer or a texture to store the Alive state of the Parent/Head Particles. This can be read by the children to synchronize their death.

In this small package, I’m joining two solutions that do just that. One solution is using a Graphic Buffer, while the other is using a Texture.

VFXG_BuffersBind_HeadInfos.unitypackage (1013.2 KB)

Note: This package has been made with Unity 6.1 Alpha that might not be already available. The ability to use RWTexture2D in HLSL directly in VFXGraph just landed. This package also contains a solution relying on Graphic buffer that could be achieved with older Unity 6 version.

Both solution relies on the same idea and steps:

  • Create a Uint Buffer/Texture with a fixed Count.
    This count represents the number of Parent to track and will often be the same as the parent capacity.
  • Create a custom Index Attribute in Init Context:
  • When Parent spawn, reset the corresponding Buffer Index.
  • Upon collision, Write the Death Value to the corresponding buffer index.
  • In the Child’s Init Context Inherit the Parent Index attributes.
  • In the Child’s Update Context, read the corresponding Buffer index and do whatever you want with the information.

Graphic Buffer:

  1. Create and Bind Buffer:

    • Create a Graphic Buffer Property in Blackboard.
      image
    • In your scene, create a Script to Declare and Bind the Buffer:
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.VFX;

//Allow to execute in Editor
[ExecuteInEditMode]

public class BindBuffers : MonoBehaviour
{
// The VFX with the exposed Graphic Buffer.
    [SerializeField] private VisualEffect vfx;
// The Size of the Buffer.
    [SerializeField] private int m_BufferCount = 64;

    
    private GraphicsBuffer m_Buffer;

    private void OnEnable()
    {
// Create a new Structured Graphic Buffer of type uint and use our count.
        m_Buffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, GraphicsBuffer.UsageFlags.None, m_BufferCount, Marshal.SizeOf(typeof(uint)));
// Set the VFX Graphic Buffer property with our previously created Buffer.
        vfx.SetGraphicsBuffer("HeadBuffer",m_Buffer);
    }

// release the Buffer.
    private void OnDisable()
    {
        m_Buffer.Release();
    }
}

  1. Parent System Setup Initialize:

    • Create a Parent Index:
uint headIndex = attributes.particleId % BufferCount;

  • Reset the Buffer thanks to the Parent index.
void WriteHeadBufferIndex(inout VFXAttributes attributes, in RWStructuredBuffer<uint> myBuffer, in uint HeadIndex, in uint data)
{
    myBuffer[HeadIndex] = data;
}


When the Particles spawn, it writes at the corresponding index the value 0 (Not :skull: )

  1. Parent System Setup Update:

    • Set up your Collision Block and Trigger Events

    • Upon Collision, Write 1 at the corresponding Buffer Index:


      This use the same HLSL function as before and writes 1, upon Collision, thanks to the HasCollisionEvent Attribute wired in the Activation Port.

    • Delete you Parent Particle:

  2. Child System Setup Initialize:

  3. Child System Setup Update:

  • In HLSL use the Inherited parent index to read the Buffer:
//notice That while it's the same buffer the usage is different has we only want to read from it.
// Having different Buffer usage is possible if made in different compute shader.
void ReadAndKill(inout VFXAttributes attributes, in StructuredBuffer<uint> myBuffer, in uint HeadIndex)
{
if( myBuffer[HeadIndex] == 1)
    {
     attributes.alive = 0;
    }
}

We’re checking the buffer at the inherited Parent Index. If the value is 1, this mean that the parent is Dead and we can kill everyone.

This can work for child strip system but also with regular child’s particles.
Unity_hcczzecO0J
Unity_AGAamwhkas

I hope this will be helpful. :sun_with_face:

NICE!

Out of curiosity, is there a way to make the particles like “run into” the surface it collides with?

Like it seems strips are a series of particles, couldn’t they individually die on contact rather than all at once?

As if they collapse into the surface.

Do you mean that you want the child particles to be attracted by the Collision surface or the Collision Hit of their respective parents? If, so instead of an uint buffer, you could use a float3 to store the Collision Position of the parent.

Now, Particles can die individually on Collision, it’s just a matter of adding a collision block and setting the Collision response to “Kill”. But what you’re asking contradicts your initial question :smiley:
But I might misunderstand what you’re looking to achieve.

I’ve just took the previous example, got rid of the “Read Parent HLSL” part, added some gravity and the same Collision shape as the parent. The behavior is set to “Kill” instead of “Collision”.
Unity_SS62xfMlfD


Oooo fascinating, I’ll work on this soon!