Search Unity

Trigger Event over Distance, how to spawn evenly between position and oldPosition?

Discussion in 'Visual Effect Graph' started by azmi_unity, Oct 31, 2021.

  1. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    The example at Vfx graph question. - Unity Forum works great using the "Spawn over Distance" node, but when using the GPU Event > Trigger Event over Distance, oldPosition can't seem to be inherited (it's set to 0,0,0).

    Any way to create smooth explosion trails, evenly spread without them clumping together?

    upload_2021-10-31_11-27-37.png

    Although, I am able to infer old position by extrapolating from velocity attribute like so. Is this accurate?

    upload_2021-10-31_11-30-54.png


    Another issue i'm seeing is the "Rate" parameter in Trigger Event over Distance don't seem to have an effect. I'm using Trigger Event Always for the good screenshot above.
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
  3. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    Unfortunately no :/
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Ok, this is interesting. Looks like Trigger Event over Distance old position is the same as position, becuase it makes no sense to inherit the previous particle old position (it would be incorrect anyway), however because events are limited by graph update delta, particles can't be spawned more frequently.
    The thing is, in theory Trigger Event Always should produce basically the same outcome as Over Distance with hight rate, but it does not in your example.

    I wanted to propose the solution with spawnIndex, but it behaves a bit strange,
    @VladVNeykov could you elaborate following case?
    upload_2021-11-2_17-21-20.png
    There is super fast particle moving upwards and it has trigger GPU event over distance to spawn red particles with X offset equal to spawnIndex (Clamp To One option is set to false and Rate is set to 5). The thing is spawn count is always 0 and spawn index does not start from 0 every time as you can see.
    Does it supposed to work like this? Or it works differently in new versions (mine is 10.7)?
     
  5. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi,
    There are a potential few pitfalls here:

    1.Trigger Event over Distance is a bit misleading, as the block is really more over Velocity:
    rateCount_a += length(velocity) * deltaTime * Rate;
    uint count = floor(rateCount_a);
    rateCount_a = frac(rateCount_a);
    eventCount = count;
    eventCount = min(eventCount,1);


    (i.e. Manually setting the Position attribute directly won't be counted as distance when using the Trigger Event over Distance block, and you'll get 0 particles triggered.)

    2. OldPosition would probably be very very close to Position as it's really just Position from last frame.

    3. Just as an FYI, you can only inherit in Initialize. You can't use the source attribute in Update / Output.

    4. Triggers are executed at the end of Update. Even if the Trigger block is above another block setting a new Position later, it will be executed after it (the UX needs some rework).
    [Edit] Trigger values inherited in the child system are derived from the values at the end of Update in the parent system, but they do execute wherever you put them.



    It's a bit hard to tell without looking at a full graph + end result, but it would be worth checking to make sure all of these points are taken into account :)
     
    Last edited: Nov 9, 2021
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    When using Trigger Event over Distance the inherited old position is the same as position.
    My guess what happens in his case and why 'trigger always' works better is that it invokes event specified amount of times, meanwhile 'trigger over distance' has default "clamp to one" set to true. This way there are more particles randomy distributed along velocity and even if there are gaps, bloom is going to fill it.

    Anyway shouldn't Triger Event Over Distance set spawnCount to some number higher than 0?
    And why spawnIndex is so strange?
    This is my graph from above by the way:
    upload_2021-11-9_14-10-48.png
     
  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    @VladVNeykov To be honest I am very confused about behaviour of rate events. I tried to reproduce electric trails from following video and I encountered strange things when trying to make it work.


    On top of what I wrote in previous two posts, very strange things happen when "Clamp To One" option is disabled - particles in stripes are missing or not spawned at all.
    Here is example graph - if you click on "Triger Event Rate (Over Distance)" and uncheck 'clamp to one' option, all stripes will not be rendered at all, they are not even spawned (?). In other test project (2020.3, graph above is from 2021.2) I managed to spawn stripes with missing particles like this:
    upload_2021-11-27_16-7-15.png

    The thing is 'Spawn over distance' without clamping is the only way to spawn electricity correctly - when enabled it can't keep up with particle speed (in my graph they are super slow). Using 'over time' will spawn particles differently when play rate changes (actually the same thing happens for clamping).
    I don't know how to tackle this problem.

    // edit: This is graph with missing particles in stripe.
     
    Last edited: Nov 27, 2021
    daneobyrd likes this.
  8. CitronMaane

    CitronMaane

    Joined:
    Nov 16, 2016
    Posts:
    15
    I've stumbled upon this exact issue.
    I tried to check the events position using particles with a small amount of random noise applied to the position to see if there were any particles that spawned on top of each other.

    Could this break the particlestrip mesh generation?
    Overlapping.png

    (In my case I was using trigger event over time because i was setting the position each frame and did not have any velocity. That said the results are exactly the same as @Qriva.

    Overlapping_Graph.png

    Here's the particlestrip for reference.
    Overlapping_Graph.png
     
    Last edited: Apr 13, 2022
  9. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    This needs to be screamed over !!!
    Manually setting position of particle using set position or by dragging transform will not trigger GPU Event correctly.

    But is there a way I can do this calculations myself and provide it manually, instead of "set velocity" block ?

    Lets just say that i have dragged the transform from one position to another and still want to trigger GPU Event over distance.
     
  10. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    This works for me:

    upload_2023-10-15_1-2-35.png

    (Disable Update Position in the Update Block first)

    But it sounds like you want to spawn more particles when you move the transform around. I'd use SpawnOverDistance for that.
     
    koirat likes this.