I am playing around with some particle code that looks like this:
myParticles.Stop();
Debug.Log(myParticles.name + " is alive " + myParticles.IsAlive());
Debug.Log(myParticles.name + " is playing " + myParticles.isPlaying);
The problem is that both isPlaying and IsAlive() return true. I would expect isPlaying to return false (because the emission has been stopped), and IsAlive() to be true (because there are some lingering particles).
If this is not how these work, can someone please explain the difference between these two?
I am working on a script that can restore a particle system to its former state after the GameObject it was attached to was deactivated and reactivated. Without a way of telling if a particle system actually playing it is proving difficult.
isPlaying will be true no matter what your emission is as long as particle system is set to play. To change it use Stop() or Pause().
IsAlive will be “false” if all particles are dead, particle system is done emitting and particle system exists on the scene at least as long as number specified in “duration” bracket. Otherwise, “true”.
Unless I am misinterpreting what you are saying, my tests don’t seem to agree with you.
Here is my test:
I created a looping particle system with the following script attached to it:
using UnityEngine;
public class Stopper : MonoBehaviour
{
void Update ()
{
if(Input.GetKeyDown(KeyCode.Space))
{
ParticleSystem myParticles = GetComponent<ParticleSystem>();
myParticles.Stop();
Debug.Log(myParticles.name + " is alive " + myParticles.IsAlive());
Debug.Log(myParticles.name + " is playing " + myParticles.isPlaying);
}
}
}
The problem is that when I run this script I get the following results:
Since I just called myParticles.Stop(), isPlaying should return FALSE, but as you can see it is returning TRUE. In fact it will continue to return true until all the alive particles have died.
It would seem that isPlaying and IsAlive() are are producing identical results.
Yes, it seems I was incorrect in isPlaying in Stop(). Pause() does set it to false though while leaving IsAlive() true.
Another time I’ve found for them to have different value is to have subsystems. IsAlive() returns true if any of particle subsystems or current system are still alive while isPlaying returns state for current system only.