Search Unity

Question How do you use VFXEventAttribute?

Discussion in 'Editor & General Support' started by v7342659018, Mar 16, 2023.

  1. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    I've already seen the following threads:
    https://forum.unity.com/threads/vfx-graph-how-do-i-access-the-vfxeventattribute-payload.755225/
    https://forum.unity.com/threads/sin...s-and-colors-from-script.855634/#post-5920883

    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:
    Code (CSharp):
    1. public class SpawnVfxTest : MonoBehaviour
    2. {
    3.     [SerializeField] private VisualEffect vfxGraph;
    4.     [SerializeField] private Color colorA;
    5.     [SerializeField] private Color colorB;
    6.     [SerializeField] private float lerpT;
    7.  
    8.     void Update()
    9.     {
    10.         if (Input.GetKeyDown(KeyCode.K))
    11.         {
    12.             var attributes = vfxGraph.CreateVFXEventAttribute();
    13.  
    14.             attributes.SetVector4("ColorA", colorA);
    15.             attributes.SetVector4("ColorB", colorB);
    16.             attributes.SetFloat("LerpT", lerpT);
    17.  
    18.             vfxGraph.SendEvent("TestSpawn", attributes);
    19.         }
    20.     }
    21. }
    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?
     

    Attached Files:

  2. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    Hello,
    Your setup was almost correct. The attribute payload from spawn context must be explicitly read in the Initialize Context to be effective:
    upload_2023-3-17_8-58-4.png
    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 VfxGraphTest_fixed.zip, 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.
     

    Attached Files:

    v7342659018 likes this.