Search Unity

Question VFX Graph Play() vs Reinit()

Discussion in 'Visual Effect Graph' started by WAYNGames, Jul 26, 2020.

  1. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Hello, I'm starting to make some vfx using vfx graph for my ability package.

    I spent some time figuring out why my particules were not working whe nentering play mode.

    Turns out, my script was calling Play() every frame.

    I did not expect the Play() to 'restart' the particule system as there is a Reinit() option as well.

    So what are the differences between the two ?

    Also is there any way to know whe na VFX is playing ? I tried aliveParticuleCount but when calling play on hte vfx the first particule does not spawn before 20ish tick so that does not work.

    We have the pause info but it's (as expected) always false even when the vfx is stoped.
     
  2. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    Hello,

    I understand, it's a bit confusing at the first glance, we are trying to clarify this in documentation and tutorials.

    > Turns out, my script was calling Play() every frame.
    It's an interesting case, here, two examples to illustrate the behavior :

    1) If your spawn context only contains a rate and if you are calling Play every frame, then, you will never emit any particles.
    upload_2020-7-27_17-28-43.png

    2) If your spawn context only contains a rate and if you are calling Play every frame, then, you will spawn two particles every frame.
    upload_2020-7-27_17-27-56.png

    This is because the event "Play" simply resets the accumulated spawn rate.

    Note that the "OnPlay" event is implicitly plugged into empty "Start" flow anchors, the following graph is equivalent to 1) :
    upload_2020-7-27_17-57-48.png

    Note that you can also chain spawn event and reproduce a "spamming" of OnPlay every frame with two contexts. I don't want to confuse you more, you can simply notice this behavior exists.
    upload_2020-7-27_17-33-24.png

    > I did not expect the Play() to 'restart' the particule system as there is a Reinit() option as well.​

    The Reinit function implies a Play invocation but it also resets completely the actual state of already alive particles, it will empty buffers and reset the internal total time.

    > Also is there any way to know whe na VFX is playing ? I tried aliveParticuleCount but when calling play on hte vfx the first particule does not spawn before 20ish tick so that does not work.
    We have the pause info but it's (as expected) always false even when the vfx is stoped.​

    The pause state is only a modifier of the delta time applied every frame (as the playRate), it forces the simulation to be "paused" with an update delta time of zero.

    In many case, the aliveParticleCount can return delayed result, it uses asynchronous readback to retrieve the actual result. If you are using a constant rate block, the first frame spawning a particle will also relies on the rate (e.g.: as in above example, if rate is "2", then the first particles trigger will be after 0.5 second)

    The effect is automatically playing if the component is active, enable and visible. For the visible part, you can force the simulation to be updated even if VisualEffect is offscreen, it's handled by the VisualEffectAsset culling flag).

    I hope it will help to better understand this, feel free to ask for more precision.
     
    Last edited: Jul 27, 2020
    WAYNGames and florianhanke like this.
  3. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Hi, thanks for the detailed answer. :)
    I'll keep digging with this info in head and won't hesitate to come back if anyy new question arise.;)