Search Unity

What is the right way to Pause particles?

Discussion in 'Visual Effect Graph' started by VMaxxx, Feb 29, 2020.

  1. VMaxxx

    VMaxxx

    Joined:
    Sep 19, 2013
    Posts:
    7
    Hello, may be is is stupid question, but how to pause particles with constant spawn rate.
    If I have single burst the function "Pause" is works as it should. But with spawn rate it is reset to default or something like that, and there is a not good looking gap...

    I've trying to set velocity to 0.0.0 and it obviously didn't help.

    So is there a livehack hot to pause the particles?

    There is an example in attach! - wall of moving particles...

    Thanks
     

    Attached Files:

    • wall.png
      wall.png
      File size:
      706.8 KB
      Views:
      532
  2. Kikimacia

    Kikimacia

    Joined:
    Jan 27, 2020
    Posts:
    17
    Hey,

    I'm super noob but just in case it can help you somehow. When you click on your graph in the hierarchy you get the little play / Pause... Button in the scene, you can pause it there can't you ?
     
  3. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @VMaxxx

    It might be worth to check the API description, as there's a good list of available properties etc.

    VFX Graph stuff resides in UnityEngine.VFX namespace. See the VisualEffect section: https://docs.unity3d.com/2019.3/Documentation/ScriptReference/VFX.VisualEffect.html

    My example below gets the VisualEffect component from the current unity object you've assigned this script to, then you can adjust the timeScale variable in the Editor UI during runtime, then the effect animation speed changes based on the time scale you set. If you set it to zero, animation is paused. You can use that property to gradually slow down down your effect to a halt, then make it move fast again after a moment. Just as an example.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.VFX;
    3.  
    4. public class AdjustVFXSpeed : MonoBehaviour
    5. {
    6.     [SerializeField] float timeScale = 1.0f;
    7.     [SerializeField] VisualEffect VFX;
    8.  
    9.     void Start()
    10.     {
    11.         VFX = GetComponent<VisualEffect>();
    12.     }
    13.  
    14.     void Update()
    15.     {
    16.         VFX.playRate = timeScale;
    17.     }
    18. }
     
  4. VMaxxx

    VMaxxx

    Joined:
    Sep 19, 2013
    Posts:
    7
    Hi @Olmi

    Play Rate doesn't work! playRate = 0 is the same as Pause function. After you return it to 1 it will not resume movement but start it from start. I think it is some how connected with Constant Spawn Rate inner work and it should be paused using some trick)
     

    Attached Files:

  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Are you sure about that? Play rate changes particle simulation speed. Is that not what you want to do? It does not cause any sort of discountinuity like simulation restarting if you change the value.

    If you want to control particle emission, and pause it, it's different issue.

    Here's a quick video I made that shows how it works, I don't see any discontinuities. And it definitely does not start from begininng after you adjust the value.

     
    Last edited: Mar 3, 2020
  6. VMaxxx

    VMaxxx

    Joined:
    Sep 19, 2013
    Posts:
    7
    Hi @Olmi

    May be I am just a noob :) It is all very strange.. Could you please share the VFX graph of your example to compare. Do you use Constant Spawn Rate and just change the VisualEffect.playRate ?

    thanks!
     
  7. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    It's very basic, you probably have set something differently. Here's screenshot of the critical things, output doesn't really matter as it's just size, color and so on over the life of a particle.

    Constant spawn, randomized 1-3 sec lifetime, and velocity that makes majority of particles go upwards. And that turbulence makes those distortions.

    And you do have to do that during play mode, if you adjust the settings... In the case of my example script.

    vfx_graph_spawn.PNG
     
  8. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    246
    If anyone else is encountering the same problem - if you set/modify velocities directly, then you have to multiply the change by delta time manually, otherwise it will apply them every frame even when timeScale/playRate are set to 0.
     
    SearchTree and sgkz like this.
  9. franck_Extriple

    franck_Extriple

    Joined:
    Oct 27, 2017
    Posts:
    20
    Thanks Olmi for sharing the CSharp code. it works well
     
    Olmi likes this.