Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Shantred · Apr 27, 2012 at 05:32 PM · particlesparticle

New Particle System Destruction?

I've noticed that in the newest version of Unity, there is not an auto-destruct option for the new particle system. My particles do not loop and are one-shot, but are still visible in the hierarchy after they've played.

Does this cause any sort of performance issue down the road if you're working on a project that uses 20+ prefab explosions per minute? If so, how can you make sure that the particle system is removed after it plays?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by chris gough · Apr 27, 2012 at 10:35 PM

create a script that simple says:

function Update(){ Destroy(gameObject, X); }

X being just a little longer than how long the particles last, so if it was a 5 sec particle system X would be 5.5 seconds

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Shantred · Apr 27, 2012 at 10:55 PM 0
Share

This is just what I needed, thanks!

avatar image chris gough · Apr 27, 2012 at 11:07 PM 0
Share

happy to help

avatar image Ralp · Apr 20, 2013 at 03:04 PM 1
Share

You can also use the following line to automatically get the particle's duration and do the same as above:

Destroy(gameObject, particleSystem.duration+0.5f);

avatar image Rafes · Mar 17, 2014 at 09:50 PM 0
Share

You can also launch a co-routine and pool particleSystem.IsAlive

Returns bool True if the particle system is still "alive", false if the particle system is done emitting particles and all particles are dead.

avatar image
2

Answer by glitchers · Jul 24, 2014 at 02:09 PM

Here is a script I wrote for this, it uses a delay with a IsAlive coroutine

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent( typeof( ParticleSystem )) ]
 public class ParticleAutoDestroy : MonoBehaviour {
 
     public float autoDestructCheckInterval = 0.5f;
 
     void Start () {
         if( particleSystem.loop )
         {
             Debug.LogError ("Particle system can't self destruct if it loops");
         }
         else
         {
             StartCoroutine( TickDelay() );
         }
     }
 
     private IEnumerator TickDelay()
     {
         yield return new WaitForSeconds( particleSystem.duration );
         StartCoroutine( AliveCheck() );
     }
 
     private IEnumerator AliveCheck()
     {
         while( particleSystem.IsAlive() )
         {
             yield return new WaitForSeconds( autoDestructCheckInterval );
         }
 
         Destroy( gameObject );
     }
 }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mattssheep4 · Oct 29, 2018 at 10:15 PM

For those using Unity 2018 (Probs 2017 and up, but can't confirm), there's a handy "Stop Action" drop down which tells the particle system what to do once it stops and all particles have died. This includes an option to destroy itself. In theory this is a better alternative than a custom script. alt text


particlesystem.png (27.7 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change particles alpha / sharedMaterial 0 Answers

ParticleSystem.Play() does not play particle. 10 Answers

Particle bug... wrong location. Simple code 0 Answers

Get all particles within trigger collider? 1 Answer

Plasma Thruster Effect (Particles?) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges