- Home /
Particle System - How can I make sure top parent end last?
I have a particle system that contains multiple children particles. Is there anyway I can make sure the top parent particle end last? (so that I can make use of the stop action Callback)
Thanks.
Can you explain more? the executive order of your particle, Is the parent particle looping or not,... If you provide more info we can provide you the nearest archive approach to your problem.
@JVLVince Thanks for reply. The particle is not looping, because I use stop action callback. Assume I create an Explosion Particle:
Parent: Explosion Smoke,
Children: Explosion Fire, Rock flying, Shocking wave.
After the Explosion Fx done, I want to call the a Callback action: Destroy. But if the Parent Explosion Smoke end before its children, its children will be destroy before completing - that's the problem.
Answer by JVLVince · Oct 10, 2018 at 08:10 AM
Well, there are various ways to archive this, but I will provide you the easiest way to implement.
First, let's talk about the idea. The idea here is set your Explosion Smoke 's loop to true, then start a coroutine to check if all the children isAlive, if not, stop the Explosion Smoke, and the StopAction will be invoked.
public class TestParticle : MonoBehaviour {
private ParticleSystem m_mainps;
private List<ParticleSystem> m_childrenPar;
ParticleSystem.MainModule m_main;
private void Start() {
m_mainps = GetComponent<ParticleSystem>();
m_childrenPar = GetComponentsInChildren<ParticleSystem>().ToList();
m_main = m_mainps.main;
m_main.loop = true;
m_main.stopAction = ParticleSystemStopAction.Destroy; // or something else
StartCoroutine(OnFinish());
}
private IEnumerator OnFinish() {
yield return new WaitUntil(() => !m_childrenPar.Exists(x => x.IsAlive()));
m_mainps.Stop();
}
}
attached this script to your particlesystem object maybe it's work.
Cheers, Vince.