Search Unity

How to handle slow motion for VFX graph effects?

Discussion in 'Visual Effect Graph' started by Stacklucker, Mar 30, 2020.

  1. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    I know that I can simulate a very smooth slow motion of my effect via the playrate parameter.

    Whenever I change the Time.timeScale of my game though ( to have my game run in slow motion: Time.timeScale = slowdownFactor), my VFX effects have a very low update rate and look laggy/stuttery. FYI I do update the Time.fixedDeltaTime accordingly to my slow down factor as well ( Time.fixedDeltaTime *= slowdownfactor).

    How can I get a smooth playback/update rate while messing with Time.timeScale? I do not think I should touch .playrate because after all, the playrate should stay at 1, according to whatever the current Time.timeScale is. But somehow I need to increase the update rate of my visual effect, right?
     
  2. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    I still haven't found a solution, but am running into the same problem with my PBR Shaders. I was reading up on the unity docs a little bit ( https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html), do I have to access the shader properties in Cg/HLSL somehow to change the _Time or unity_DeltaTime properties? I have no experience coding shaders and don't know wether thats the correct approach or not, but maybe someone here knows?

    Any help would be much appreciated. It seems like a problem which should have an easy solution, since so many games are making use of slow motion, but somehow I have trouble finding other people struggling with the same problem online.
     
  3. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    I have finally found a solution, but I do not understand why the solution works.
    Clicking on the Visual Effect in the Project Manager and selecting Update Mode : Delta Time (instead of Fixed Delta Time) resolves the issue. The particles are now buttery smooth when slow motion is triggered.

    The part that's got me confused is, that I also decrease the Time.fixedDeltaTime (by the same amount that I decrease Time.TimeScale) every time I enter slow motion mode and other physics objects behave smooth in slow motion.

    Could it be that the Fixed Delta Time that you can select in the Update Mode (in the Insepector of the VFX Effect) is not the same as the physics fixed delta time? After all, there is a different "Fixed Time Step" option under VFX in the Project Settings tab. Talk about making things complicated...
     
    BennyKokMusic likes this.
  4. ibearjp

    ibearjp

    Joined:
    Sep 24, 2014
    Posts:
    15
    Noobs myself.
    Hope this helps.
     
  5. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    I do not know how exactly this works under the hood as documentation does not explain it (or I can't find it), but as you mentioned VFX has additional fixed time step option. I am not sure if it's based on fixed delta time or it's completely separated, but it must changed along with timescale. I cache initial value in defaultVFXFixedTimeStep and then:
    Code (CSharp):
    1. Time.timeScale = newTimeScale;
    2. Time.fixedDeltaTime = defaultFixedDeltaTime * Time.timeScale;
    3. VFXManager.fixedTimeStep = defaultVFXFixedTimeStep * Time.timeScale;
     
    Siethu likes this.
  6. toolboxno9

    toolboxno9

    Joined:
    Jan 15, 2017
    Posts:
    1
  7. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    It is useful, but not the same. I will complete my last post a bit to make it more detailed.

    • If you need to do slow motion effect the best choice is VFXManager.fixedTimeStep, simply because most likely you want to change play rate of all VFX in the scene. However this value is parameter stored in project settings and it will not be restored when exiting playmode (or at least it was not in 2019.4). You must cache it in some variable and restore later after use - for example in OnDestroy.
    • To slow down single instance there is vfx.playRate, but if you have multiple spawners in your graph, they will be all affected by this. This may be not desired and one solution is to split them.
    • There is also rate parameter in Constant Spawn block, but it has nothing to do with slowing down time.
      It changes how often particles are spawned, but their update speed is unaffected. This option is useful for example when you want to increase the amount of exhaust produced by the car.
    • One more and last solution (it should work, but I didn't test it) to create the slow motion is to disable particle update options and make them manually. You can create exposed parameter 'timeSpeed', multiply delta by this value and use it to update position, age, etc..
      In theory this should allow to have one graph with multiple different speeds for each spawner.
      One more note - deltaTime is affected by vfx.playRate.
     
  8. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    Does this mean VFX graph is capped to 60fps by default?