Search Unity

Question How do you use VFXEventAttribute?

Discussion in 'Visual Effect Graph' started by v7342659018, Mar 16, 2023.

  1. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    Hi, I've made this post in a different forum before I realized there was a VFX graph specific forum.

    https://forum.unity.com/threads/how-do-you-use-vfxeventattribute.1413261/

    To summarize, I've tried to set up a basic scenario that passes in some data from VFXEventAttribute into the vfx graph and do some arbitrary processing on that data. However, it seems like the data just doesn't get passed into the graph for some reason. I've attached the unity project files for this test case here as well.

    Is there a working example of a VFX graph that uses a custom attribute?
     

    Attached Files:

  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    You mixed two different things. Event attribute is data particles get when they are created, for example velocity, position, color. If you pas them with the event then you can initialize all those particles with some spawn unique attributes.

    Based on the code in link above you wanted to set graph properties (ColorA, ColorB, LerpT). This is different mechanism and you set them directly with methods like
    vfxGraph.SetFloat();
     
  3. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    I want to set the property of each individual particle as it spawns, not the graph properties.

    For example, I would trigger the
    TestSpawn
    event with some attributes containing different colors/etc, and that would cause two particles of different colors to be spawned.
     
  4. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    upload_2023-3-16_15-2-0.png

    To add some more details, in the simple example linked above, I want to pass arbitrary data into these custom attribute nodes with each spawn event.

    From this post, it seems that there is definitely some way of passing in custom data into particles as they get created, and the eventAttribute from this API is presumably how you pass the custom data in. However, in the script I linked, the data isn't being passed into the event for some reason.
     
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Right, sorry my bad - I mistook your component VfxSpawnTest as part of properties of the graph.

    So first of all:
    You can send event payload, but this data will be passed to all spawned particles, so if you mean here literally individual particles, then you can't do that as it would require array of payloads. This can be done only via graphics buffer or texture.

    If you pass data in event payload it must be inherited, this means you need to put this kind of block in the initialize context:
    upload_2023-3-17_0-36-31.png
    However there is one problem, Julien said in other thread you can pass any custom attribute, but this is not true, he corrected it several posts later. You can use existing attributes like position, color, size, but not the custom one. I don't know if they forgot to fix that or it's intentional at this point, but in my (2021.3) version ui does not allow that. However, maybe this is fixed in 2022 - I don't know, you need to check.
     
  6. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    In the following image from VladVNeykov though, it doesn't use any sort of inherited block. Is his example wrong then?


    Also, if it's only a UI issue that's blocking the feature, then is it possible to set this node up externally, by manually editing the vfx file? Or does this feature just not exist completely?

    It seems quite strange to me that the documentation for VFXEventAttribute would exist when there's no way of actually using it... even more so that this hasn't been resolved after multiple years.

    And also, what are the GetCustomAttribute/SetCustomAttribute nodes used for then? If the inherit nodes is the only way to obtain the values of custom attributes, what is the point of having these other two nodes?
     
  7. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    Wait also, in this API documentation, it's using a custom attributes named "spawnCount", which doesn't have a corresponding inherit block. So is that documentation wrong as well?
     
    Last edited: Mar 17, 2023
  8. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    He probably made this picture for demonstration purpose, there is just constant (0) value. He shows you can feed it with data, but image does not show how to actually inherit.

    The feature exists and I personally use it, but it just does not allow custom properties.
    I am unable to answer if this can be hacked by manually editing the file.

    Get and Set Custom Attribute is internal for the graph, and it has nothing to do with inheriting data itself.
    You can create custom attribute and use it like any other attribute (color) to calculate something or pass to shader, and you can feed it with any data you want (it doesn't have to come from an event).
    Inheritance block is used to feed it with data from the c# event instead of setting that value from other custom source.

    Documentation is correct here, "spawnCount" is special system attribute used by direct link feature, while "direct" is actually event name, not attribute.
     
    Last edited: Mar 17, 2023
  9. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Apparently I am simply stupid. When you mentioned Get/Set custom property something rang on the back of my head and several minutes I realized I might be wrong.

    Inheriting is actually just setting location to "source" instead of "current" and for some reason I never thought about the fact that GetCustom has location property too and I could change it.
    Long story short change it to source and it works.

    upload_2023-3-17_5-56-23.png
    For clear image: inherit source velocity block is equal to setting velocity with get velocity from source.
     
    v7342659018 likes this.
  10. v7342659018

    v7342659018

    Joined:
    Feb 17, 2018
    Posts:
    12
    Ah, that seems to work for me! For future reference, here's the full graph/code setup that I have now, in case anyone else also runs into this issue (the documentation for this is pretty lacking unfortunately).
    upload_2023-3-16_22-36-56.png

    Thanks!
     
  11. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    287
    Thank you!

    I wanted to pass data from a 'custom attribute' to particles spawned by 'GPU event' when original particles died. But I noticed there was no 'inherit Source Custom', but using the 'Get Attribute Custom' with Source in the 'initialize Particle' of the 'GPU Event particles' I was able to set this value in the new particle with a Set Attribute Custom.

    upload_2023-6-29_12-4-2.png