Particle System and Time Scaling

Hello,

I’m using a particle system TriggerModule and registering a collider against it to receive OnParticleTrigger() callbacks so I can tell when a particle is inside the collider.

I also have allowed the user to scale simulation time (setting Time.timeScale). So the player can set the time scale to 2x or 3x to simulate faster. Note that all of my code is done in FixedUpdate as I need repeatable, consistent playback of the simulation, regardless of framerate. I essentially set a bool flag in OnParticleTrigger so that on the next FixedUpdate call, I can make a decision on if the collider currently contains a particle.

At 1x, I seem to get consistent behavior. While the particle system is inside the collider, I get what seems to be a OnParticleTrigger() callback every timestep (0.02s FixedUpdate rate).

At 2x/3x/etc, it seems like the particle system collision triggering isn’t running every Physics step (FixedUpdate()). I’ll get a call back at 0.04, 0.08, 0.12 as if the detection process is scaled. What this means is that I cannot use the bool flag described earlier to tell if there is currently a particle inside the collider since OnParticleTrigger isn’t called every timestep.

But maybe I’m getting something wrong here?

  1. Does anyone know anything about time scaling and particle systems that could help me?

  2. Is particle system collision done at the fixed timestep rate, as part of the physics loop described here Unity - Manual: Order of execution for event functions ?

the particle update is not done at fixed update frequency but you can call ParticleSystem.Simulate yourself in FixedUpdate if you need it to be in sync with that update rate.

Thanks for your reply. What is the particle system update linked to when not manually called via ParticleSystem.Simulate?

it has its own fixed update frequency, defined by Max Particle Timestep in the Time project settings. But if the delta time isn’t larger than that value, it just does an update based on whatever Time.deltaTime is for each frame.

So it sounds like I have 2 options if I’d like my particle systems to run every FixedUpdate (0.02s):

  1. Set Max Particle Timestep to 0.02s, noting that it may run faster than that if the frame time is smaller?

  2. Keep a reference to all my particle systems and manually call Simulate every FixedUpdate. Could you explain a bit more about what the fixedTimeStep flag does there?

Also, does 'Maximum Allowed Timestep` play into this at all?

  1. probably won’t give you any guarantees of being in sync

  2. should work - pass false for fixedTimestep Unity - Scripting API: ParticleSystem.Simulate

Why does Unity Update its particle systems based DeltaTime + Clamps it using the MaxParticleTimestep ? woudn’t that still lead to unexpected behaviors ? (such as when using DeltaTime rather than a FixedDeltaTime, accumulations happen overtime of very small values changes which can change the particle system appearance, particular example is leading to bursting or very weird “shapes”) ? if not how does unity mitigate this ?

MaxParticleTimestep is used to ensure the simulation doesn’t degrade too much if the time steps get too large. if they do, it does multiple smaller updates. It will keep things “approximately” the same regardless of delta time but it’s not exact.

It’s been done like this for a lot of years, i couldn’t say if it’s the best way.

So yeah basically you’re right :slight_smile: