- Home /
auto destruct a particle system.
I've been using this code I found from other answers of the same question, and it's generally worked out rather well.
function Update ()
{
if ( particleSystem != null && particleSystem.particleCount == 0 )
{
Destroy ( gameObject );
}
}
I just attach that to the particle system in question and usually have had no issues. But I've tried to attach it to an explosion I've made, and for some reason the explosion now doesn't show up at all, it just instantly get's destroyed!
Anyone have any thoughts?
I am using the new system without the "auto destruct" toggle, I didn't know it had a name though.
Answer by Apinaheebo · Aug 05, 2013 at 07:41 PM
Try this:
private var ps : ParticleSystem;
////////////////////////////////////////////////////////////////
function Start () {
ps = GetComponent(ParticleSystem);
}
function Update () {
if(ps)
{
if(!ps.IsAlive())
{
Destroy(gameObject);
}
}
}
Thanks for the script, I tested it out and it seems to have solved the issue.
Answer by wijesijp · Aug 05, 2013 at 03:48 PM
maybe at the beginning partial count is 0, it take some time to start ...
There is no Prewarm or start delay.
Duration : 0.10, Looping off, Prewarm off, Start Delay : 0, Start LifeTime : 1, Start Speed : ( random 2 - 3 ), start size : ( random 1 - 2 ), start rotation : 0, start color : ( white ), gravity multiplier : 0, Inherit Velocity : 0, Simulation Space : Local, Play on Awake : on, $$anonymous$$ax Particles : 300. Emission : Rate : 300, bursts : Time : 0.10 Particles : 150, Shape : Sphere : Radius : .3111069, Color over Lifetime : ( alpha gradiant from a white - yellow - red - black ), Size over Lifetime : ( linear from 1.0 - .55 ), Renderer : Billboard : Normal Direction : 1 $$anonymous$$aterial : Default-Particle : Sort $$anonymous$$ode : None, Sorting Fudge : 0, Cast Shadows : on, Recieve Shadows : on, $$anonymous$$ax Particle Size : .5
Answer by davidsubba · Dec 09, 2013 at 09:43 PM
I have a particle prefab and attached this script, it works.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111602im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particle system play too late (c#) 1 Answer
How to destory any object that collides with a particle in a particle system?? 1 Answer
error in destroying bullet prefab 1 Answer
OnTriggerEnter to Destroy Objects not working Correctly 1 Answer
When An Object Doesnt Exist, Help Making a Variable In Another Script Change 1 Answer