How do you use VFXEventAttribute?

I’ve already seen the following threads:

I’m trying to pass some custom parameters into a vfx graph to affect how the particle should spawn, but it seems like VFXEventAttribute just doesn’t work at all.

Here are the vfx graphs that I’ve tried using (both of them result in a completely black particle):

Here is the script that I’m using to spawn the particles:

public class SpawnVfxTest : MonoBehaviour
    [SerializeField] private VisualEffect vfxGraph;
    [SerializeField] private Color colorA;
    [SerializeField] private Color colorB;
    [SerializeField] private float lerpT;

    void Update()
        if (Input.GetKeyDown(KeyCode.K))
            var attributes = vfxGraph.CreateVFXEventAttribute();

            attributes.SetVector4("ColorA", colorA);
            attributes.SetVector4("ColorB", colorB);
            attributes.SetFloat("LerpT", lerpT);

            vfxGraph.SendEvent("TestSpawn", attributes);

And here is the gameobject that the above script is attached to:

I’ve also attached the unity project files below.

My expectation is that the color of the result spawned particle is lerped between red and green. However, it only spawns a black particle, so it looks like the colors/etc aren’t being set.

I’m aware that there are workarounds that can make this use case work, but my real use case is more complex, and I will need these custom attributes to work. What am I missing in setting up the custom attributes?

8882019–1213572– (57.2 KB)

Your setup was almost correct. The attribute payload from spawn context must be explicitly read in the Initialize Context to be effective:

We are working on UX improvement to provide a custom attribute blackboard. In case of built in attribute, you could use “Inherit Source (…)” to achieve the same operation.

Here, in action:

The post is embedding the modified project, I only changed the file “TestVfx.vfx”.

By the way, I’m glad to see the direct link feature used in real world cases, you can find additional information about this feature in this thread .

8882961–1213782– (56.9 KB)

1 Like