- Home /
IsAlive() and Simulate() of ParticleSystem used simultaneously
What happens with IsAlive() function, when the ParticleSystem is not controlled via Play/Stop/Pause? I'm asking because it seems that it's not working properly, when taking advantage of Simulate() rather than functions that I've just mentioned.
EDIT: When I've changed the code and utilised Play() and Stop() to control the ParticleSystem the behaviour of IsAlive started to work correctly. So why Simulate() doesn't flag IsAlive() properly after surpassing delay + duration + startLifetime time boggles my mind...
"it seems that it's not working properly", how so? What are you seeing and how does it differ from the behavior of Play/Stop/Pause? Some example code might help in explaining what you are doing.
I've wrote a simple wrapper to simulate my ParticleSystems within the FixedUpdate function [1] (I'm not using Play/Stop/Pause because of a choppy movement explained in the question [1]). $$anonymous$$y PS objects are pooled, and they should return automatically to the pool after all given PS particles disappear (usage of IsAlive which returns true all the time).
using UnityEngine;
using System.Collections;
public class PoolReturnWhenAllPsDead : $$anonymous$$onoBehaviour {
private ParticleSystem[] ps;
private PoolItem poolItem;
void Awake() {
ps = transform.GetComponentsInChildren<ParticleSystem>();
poolItem = transform.GetComponent<PoolItem>();
}
void Update() {
for(int i = 0; i < ps.Length; ++i) {
if(ps[i].IsAlive())
return;
}
poolItem.ReturnToPool();
}
}
[1] http://answers.unity3d.com/questions/661969/particles-lag-choppy-movement.html