Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

VFX Graph - How do I access the VFXEventAttribute payload?

Discussion in 'Graphics Experimental Previews' started by turboturboturbo, Oct 4, 2019.

  1. turboturboturbo

    turboturboturbo

    Joined:
    Dec 2, 2018
    Posts:
    20
    I want to spawn hundreds of explosions in quick succession.
    Each explosion varies in position, duration, color, intensity etc...

    Currently I am instantiating a new VFX graph object for each explosion and changing their exposed parameters, however this seems like a bad idea?

    Instead I would like to create a single VFX graph and send VFXEventAttributes as parameters:

    Code (CSharp):
    1. string eventName = "OnExplode"
    2. void SendEvent(string eventName, VFXEventAttribute eventAttribute = null);
    My question: How can I access these attributes/values within the blocks?
     
    Last edited: Oct 4, 2019
  2. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    167
    You can access it in the initialize context using get source attribute
     
  3. turboturboturbo

    turboturboturbo

    Joined:
    Dec 2, 2018
    Posts:
    20
    Hi Julien,

    When I do the following:
    Code (CSharp):
    1. _attrib = _vfx.CreateVFXEventAttribute();        
    2. _attrib.SetVector3("color-1", color);
    3. _vfx.SendEvent("OnManualSpawn", _attrib);
    I can't find the attribute "color-1" in the node graph editor. Am I misunderstanding how this works?
     
  4. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    167
    You need to use custom attributes nodes if you're not using built-in ones. You can activate them in preferences / vfx, enable use experimental blocks / operators
     
  5. turboturboturbo

    turboturboturbo

    Joined:
    Dec 2, 2018
    Posts:
    20
    They are currently activated but the only thing I can find is "Get CustomAttribute (Float)". I cannot find the "color-1" attribute.

     
  6. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    167
    In the inspector, there should be an option to set the name and type of your custom attribute
     
  7. turboturboturbo

    turboturboturbo

    Joined:
    Dec 2, 2018
    Posts:
    20
    Thank you. I am able to set up the custom attribute getter, however it doesn't seem to work. Do you see anything wrong here?

    Code (CSharp):
    1.  
    2. //this is called rapidly with different parameter values
    3. public void Activate(float duration, Vector3 color, Vector3 position)
    4.     {
    5.         _attrib = _vfx.CreateVFXEventAttribute();
    6.         _attrib.SetVector3("_position", position);
    7.         _attrib.SetVector3("_color", color);
    8.         _attrib.SetFloat("_duration", duration);
    9.         _vfx.SendEvent("OnManualSpawn", _attrib);
    10.     }


     
    Last edited: Oct 5, 2019
  8. turboturboturbo

    turboturboturbo

    Joined:
    Dec 2, 2018
    Posts:
    20
  9. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    167
    I checked and there's is currently no way to specify source in the get custom attribute operator, this is a UI issues only but it prevents you to do what you want. Sorry about the false info. So you need to use built-in attributes at the moment (color instead of _color for instance)
     
  10. glacuesta

    glacuesta

    Joined:
    Nov 30, 2017
    Posts:
    3
    bump on this topic. Seemed like a dead end then, and it still seems like a dead end now? Basically, how does one access the event attributes (passed from script) in the node graph?
     
unityunity