I’ve got a script attached to a particle system with Trails. The script modifies the position each frame using Get/SetParticles. The problem is that the Trails module seems to take into account not only the position of the particle system simulation but also the position of SetParticles calls. So you end up with a mid-frame deviation from the actual path of the rendered particle (a green ball in this case), which is the composite of the particle system simulation and the effects of the script. This makes the trail have an undesirable zig-zag motion that is not apparent in the leading particle at render-time:
I’ve tried doing the particle modifications in both Update and LateUpdate, and they produce slightly different results but neither end up with the desired result, which is a trail that follows the path of the actual particle’s positions at render-time.
OK so that sort of helped, but there’s one more issue which I figured out. With the method above, the trail looks good up until the trail segment next to the particle:
You can see the particle is rendered at the desired position but the particle trail is not taking into account the position change made by the script in the current frame, only the previous frame. So the solution is to call Simulate at the end of FixedUpdate, after the script changes the particles:
Hard to say exactly what’s causing this behavior, but, based on the information, I suspect the following:
The system definitely should be paused (good fix)
calling SetParticles will move the particles, but it does not cause the trail module to add points to the trails
Points will only be added to the trails via a call to Simulate
If you call Simulate with a non-zero timestep, it will be animating the particles, which could cause the zig zags you see (you are overriding their “desired” path with SetParticles, then Simulate moves them again)
if you call Simulate with a 0 timestep, i suspect it will bail out and not do anything, otherwise that would be a good fix!
I think there are 3 possible fixes. The first 2 are recommended above the other
Make sure the particle velocity is set to 0 for each particle, before calling SetParticles (This means that the call to Simulate wont move them again, which i think causes the zig-zag)
Or just set the Start Velocity to 0
Alternatively, call Simulate with a very small timestep (not Time.deltaTime) and set the fixedTimestep agument to false. But this is a bit more of a hack, really.
Thanks @richardkettlewell , that’s great information. Sorry I wasn’t clear in that last post, but I did fix the problem 100% by moving the call to Simulate() to the end of FixedUpdate, which makes sense after reading your explanation. I don’t think I can set the particle velocity to zero because I still want the particle system to do it’s simulation (I’m using the noise module in this case). My script just does some blending and tweaks to the particle properties as it goes along. I’m happy with the results now.
Question: in a solo particle system with no script interference, does it run its simulation in fixed time steps? When does the simulation get updated within the typical event order?
No need to apologise - it wasn’t that you were unclear, it’s just that there’s only so much I can figure out from a forum post vs. looking at an example project
Yes - there is an option in the Time Manager to choose the timestep. This is important for ensuring that the particle simulations are deterministic. There is a fixedTimestep parameter on the Simulate script function, which lets you disable, and run with variable timesteps, if you prefer.
OK now the zigzag makes sense because when I was adjusting the particles on Update, multiple simulations would happen without the influence of my script (depending on the frame rate). Running in FixedUpdate time ensures that every tick of the particle simulation has a corresponding change done in my script.
@richardkettlewell
This is the issue I’m having. If I’m using SetParticles to place my dusty particle world, and SetParticles to move them about (in relation to the players tranform.forward) how do I then enable the trail module on the system ??
I haven’t been able to get simulate to work. I’m creating an array of particles, setting their position to be all around me and then calling SetParticles to place them over and over (not using Emission Module)
The dusty world looks perfect, but I would really like to get the trails working
It’s hard to say if it’s possible without seeing your script/project, but trails don’t work too well with SetParticles because the trail data isn’t copied in/out of script in the ParticleSystemParticle struct.
I suspect an easier approach may be to use a both sub-emitter instead, and on that sub-emitter use distance emission (remember to set proper velocity in SetParticles on parent system). Then use Ribbon mode trails on the sub emitter, not the parent, and enable the Split Sub Emitter Ribbons option. That might work… (oh and probably set Render Mode to none on the sub emitter, to get rid of its default billboards)