Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by rd_mcn · Feb 28, 2018 at 08:54 AM · particlesdestroy

Destroying a game object with particles waits for end of particle life

I have the following to destroy a game object (missile) which has a particle component:

 GameObject energyBolt= Instantiate( missilePrefab, transform.TransformPoint( 0.0f, -0.25f, 5.0f ), Quaternion.identity );

 Destroy( energyBolt );

but the missile doesn't disappear from the editor or the play area for a few seconds, which seems linked to the duration of the particles.

Is this a known issue?

Comment
Add comment · Show 7
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 Xpartano · Feb 28, 2018 at 09:04 AM 1
Share

Hi rd_mcn, If you use Destroy(missile); the object should just disappear, no matter if it has particles or not. To clear things out, what is the structure of your missile object? Does it contain the particle system as a child object? Could you give me more info about it so I can help you? Thanks ! :)

avatar image rd_mcn Xpartano · Feb 28, 2018 at 09:15 AM 0
Share

Thanks for your response; it should indeed disappear but it is failing to do so for a few seconds. The missile object has the following components: Particle System, Sphere Collider, Rigidbody, Audio Source

avatar image Xpartano rd_mcn · Feb 28, 2018 at 09:21 AM 0
Share

$$anonymous$$mm... In your script is missile a GameObject type of variable or it's another type?

Show more comments
avatar image rd_mcn · Feb 28, 2018 at 09:22 AM 0
Share

It was created with an Instantiate() and the object returned is being stored, when Destroy is called I have a Debug line that shows it being called. The object is destroyed but only a few seconds later.

2 Replies

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

Answer by rd_mcn · Mar 01, 2018 at 07:51 AM

I have finally worked it out and I think others may find this helpful.

 Debug.Break()

runs the statements following it before the game pauses in the editor (possibly to the end of the frame processing). This entailed that the Destroy() had already been completed when the game had paused which led me to following the wrong missile.

D'oh.

If you wish to test it, then you can place a Debug.Break() in your code followed by some other statements, including debug logging and you will see these in your console when the Debug.Break() is executed.

This isn't specified in the documentation that I had a look through and is well worth knowing about.

Thanks again to everyone who helped along the way.

Comment
Add comment · Show 1 · 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 Xpartano · Mar 02, 2018 at 09:02 AM 0
Share

Good to know. Thanks for sharing! :)

avatar image
0

Answer by dishant27 · Feb 28, 2018 at 10:18 AM

The idea is to get the lifetime of the particle and destory the energyBolt after that duration.

Please try something like this after instantiating the energyBolt: float duration = energyBolt.GetComponent ().main.startLifetime; Destroy(energyBolt, duration )

Comment
Add comment · Show 14 · 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 Xpartano · Feb 28, 2018 at 10:22 AM 0
Share

If I'm not missunderstanding the OP, he wants the bolt to disappear even if the particle system is still running :/ and of course, if I misunderstood him, your answer should be a good solution! ;D

avatar image rd_mcn · Feb 28, 2018 at 10:23 AM 0
Share

Thanks for that; the particles loop around a 5 second duration. The destroy should happen when the GameObject collides with another object; not after just one cycle.

avatar image dishant27 rd_mcn · Feb 28, 2018 at 10:33 AM 0
Share

In that case, you can attach a script to missile and write the code in OnEnable method: 'float duration = gameObject.GetComponent ().main.startLifetime; Destroy(gameObject, duration )'. If the gameobject collides with someother gameobject before lifecycle, you can destroy it immediately using OnColliderEnter.

avatar image Xpartano dishant27 · Feb 28, 2018 at 11:02 AM 1
Share

When you call Destroy(gameObject); the object should just be destroyed. That is the main problem here, and we are trying to find out why something that should be happening is not happening. :/

Show more comments
avatar image rd_mcn · Feb 28, 2018 at 11:29 AM 0
Share

I tried the Clear() function in the particle system but it doesn't solve the issue :-(

avatar image dishant27 rd_mcn · Feb 28, 2018 at 11:33 AM 0
Share

But, it's working for me. Can you share the code which you tried with Clear()?

avatar image rd_mcn · Feb 28, 2018 at 11:40 AM 0
Share
 if( Time.timeSinceLevelLoad - missile.timeCreated > timeExpiry$$anonymous$$issiles || missile.energyBolt.GetComponent<EnergyBolt>().destroyed == true )
 {
     missile.energyBolt.GetComponent<ParticleSystem>().Clear();
     Destroy( missile.energyBolt );
 }

missile is a structure and the energyBolt is the GameObject.

avatar image dishant27 rd_mcn · Feb 28, 2018 at 11:54 AM 0
Share

Try to test it in a separate empty scene without any if condition. Just destroying the gameObject after some seconds using Invoke().

avatar image Xpartano rd_mcn · Feb 28, 2018 at 02:38 PM 0
Share

And you say that if you put a Debug.Log inside that if, the line is printed at the same moment it is called but the missile gets destroyed a few seconds later?

avatar image rd_mcn · Feb 28, 2018 at 10:32 PM 0
Share

Thanks for the advice (apologies for the delay in replying am in Australia and sleep was needed). I am planning on reproducing this in a test project to send as another bug report to Unity; firstly to ensure it is Unity and not something I've done.

Thanks for everyone's help; mostly I just wanted to know if it was a known issue.

Show more comments

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

83 People are following this question.

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

Related Questions

How to destory any object that collides with a particle in a particle system?? 1 Answer

Audio and Particles on Trigger 0 Answers

Blocking particles then destroy then reduce health 0 Answers

Autodestruct multi-particle system 2 Answers

How to turn object into scrap when hit hard? 0 Answers


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