I would like to rewind a particle system. I believe I should be able to do it by setting the time property, as the scripting reference made me believe:
Use this to read current playback time or to seek to a new playback time.
I see that we can rewind particle systems in the editor by scrubbing time. However I’m not having any luck with rewinding a particle system in code. Here’s what I’ve been trying it with:
public class RewindParticle : MonoBehaviour {
public float AfterSeconds = 2.0f;
public bool rewinded;
private float rewindStartParticleTime;
private float rewindStartTime;
void Update () {
if (rewinded) {
float rewindToParticleTime = rewindStartParticleTime - (Time.time - rewindStartTime);
if (rewindToParticleTime > 0.0f) {
Debug.Log("rewinding to time " + rewindToParticleTime);
particleSystem.time = rewindToParticleTime;
Debug.Log(particleSystem.time); //this corrently prints what rewindToParticleTime has
}
}
if (particleSystem.time > AfterSeconds) {
if (!rewinded) {
rewinded = true;
Debug.Log("rewinding");
rewindStartTime = Time.time;
rewindStartParticleTime = particleSystem.time;
//these didn't help either
//particleSystem.Stop(); //this stops it for good
//particleSystem.Pause(); //this just pauses it
}
}
}
}
Here’s what the output looks like. This starts after 2 seconds. I believe my code is correct:
rewinding
rewinding to time 1.997295
1.997295
rewinding to time 1.980445
1.980445
This goes on until it reaches close to zero. However, the particle system that I’m looking at doesn’t care, it just plays as if I’m not setting the time property at all.
The conclusion that I reached so far is that this is a bug and Unity simply ignores setting the time property of ParticleSystem instances. Am I missing something or is this really a bug?
Thank you.