Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

How to update the visual effect simulation manually

Discussion in 'Visual Effect Graph' started by BTables, Apr 24, 2020.

  1. BTables

    BTables

    Joined:
    Jan 18, 2014
    Posts:
    60
    I'm using the Visual effect for a particle simulation with some external elements that aren't framerate bound and would like to explicitly tell the effect when to update.

    It appears there are 2 different methods that should do what I need:
    VisualEffect.AdvanceOneFrame
    and
    VisualEffect.Simulate

    The docs for AdvanceOneFrame mention the paused property on the visual effect being the controller for if the simulation is stopped, however it appears all this does is scale deltatime to 0 and still executes the simulation.

    This isn't ideal but I can work around it by branching if deltatime <= 0 to not do any work in the particle update.

    At this point I have a simulation that doesn't do anything (expensively) unless I tell it to. The only problem here now is when I call AdvanceOneFrame, it works about 90% of the time, and intermittently does nothing for a frame, can't see any pattern for it. As I am decaying something outside the system once per frame, having it drop frames is a problem and I can't see a way to detect the frame drops.

    Option 2 was using Simulate, this however runs exactly 2 frames each time I call it when the simulation is paused (with 1 frame as the count parameter). On the brightside it doesn't skip intermittent frames.

    Is there a way around this? I would have expected an option in the UpdateMode setting of "Manual" and for these update methods to do as they say on the box.

    Alternatively can you think of any ways to bind the Visual effect update to another piece of C# code to ensure that they always get run together? Where and when the Visual effect gets updated and rendered to the scene seem undocumented but from my testing it seems to work similar to the Animator (just after update before lateupdate). I a hesitant to use anything on the main render loop as there looks to be some magic around scaling up deltaTime steps for slow running things. I see the max delta time field but don't trust its implicit behaviour.

    There is always the option to go back to hand rolled compute shaders, but thought this might be a good new use for the system, everything else is working fine, just need it to stop changing the simulation when my FPS changes.
     
  2. BTables

    BTables

    Joined:
    Jan 18, 2014
    Posts:
    60
    Well after that wall of text I tested changing the update mode to deltaTime on the Visual Effect asset and running AdvanceOneFrame and it seems to have fixed the random frame drops. Whatever update limiting mechanism that was running on fixedDeltaTime must have been kicking in sometimes during manual updates despite them being orders of mangitude slower than the fixedDeltaTime and it being paused.
     
unityunity