Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
-1
Question by ONCT · May 18, 2017 at 11:08 AM · destroyparticlesystemerror-messageparent and child

Destroy child with Particlesystem will cause error

Here is my ParticleSystem like this

alt text

And every child is contain ParticleSystem

But when I destroy child at runtime, it cause error

MissingReferenceException: The object of type 'ParticleSystem' has been destroyed but you are still trying to access it.

I think the problem is the parent still playing ParticleSystem, and I destroy the object or ParticleSystem suddenly.

But interestingly, it only appear when I click on the particlesystem. if I don't focus on the particlesystem, it just be destroyed with no error.

But i still want to fix it.

Is there any idea to deal with the condition

a.png (3.1 kB)
Comment
Add comment · Show 10
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 Vandarthul · May 18, 2017 at 12:31 PM 0
Share

You should provide us your sample code on how you manage your system. With the information you've provided, we only can assume things that you've done, which will not be very helpful to you.

avatar image ifurkend Vandarthul · May 18, 2017 at 12:39 PM 0
Share

I agree with you, this is a common case of poorly asked question. But I do think the result is weird and worth filing a bug ticket. @ONCT, if you have decided to file a bug report, try to reproduce the issue in a much simpler setup, so you can just export $$anonymous$$imal involving files to a unitypackage. In "help-report a bug...", remove your project folder from the "attached files" and ins$$anonymous$$d attach your unitypackage specifically prepared for reporting your issue, this way the Unity technicians will waste less time in verifying your issue and delivering a fix quicker.

avatar image ONCT · May 24, 2017 at 02:41 AM 0
Share

Here is my simple code:

  public class SelfDestroy : $$anonymous$$onoBehaviour
  ParticleSystem PS;
  AudioSource au;
  private void Start()
  {
      PS = GetComponent<ParticleSystem>();
  }
  private void Update()
  {
      if (gameObject != null && PS != null)
      {
          if (PS.isPlaying == false && transform.childCount == 0 && PS.main.loop == false)
          {
                  SelfBomb();
          }
      }
  }
  private void SelfBomb()
  {
      PS.Stop();
      PS = null;
      Destroy(transform.GetComponent<ParticleSystem>());
      Destroy(gameObject, 0.2f);
  }

It will automatically destroy it self when finishing the particlesystem.

and as i said, it cause: alt text

Thanks for your reply, and apologies for the delay in getting back.

avatar image TonicMind ONCT · May 24, 2017 at 06:28 AM 0
Share

Try implementing an objectpooler ins$$anonymous$$d of using GetComponent() and Destroy. This is not a bug afaict. You are simply removing your object from memory when it is needed. That is why the error message is "$$anonymous$$issingReferenceException: The object of type 'ParticleSystem' has been destroyed but you are still trying to access it"

Object Pooler tutorial: https://unity3d.com/learn/tutorials/topics/scripting/object-pooling

avatar image ONCT TonicMind · May 25, 2017 at 07:32 AM 0
Share

I have tried your suggestion, but it looks like not completed deal with my dilemma.

Here is my situation: I cache a effect in the game(ex:fireball), and when i cast the spell, it instantiate the effect at once, I think it is not okay that when every effect had play done, move it to objectpooler, that will stock many used effect, so i need to destroy it sometime, and the error appeared at all.

Anyway, it doesn't cause any bug or anything to the game, I think i can shelve it temporarily.

and thanks for your answer.

Show more comments
Show more comments
avatar image TreyH ONCT · May 25, 2017 at 01:42 PM 1
Share

There's a delay on destroying the object, but is there a script on that object trying to reference that (now destroyed) particle system anywhere else? Where is that error co$$anonymous$$g from?

avatar image ONCT TreyH · May 26, 2017 at 02:14 AM 0
Share

I tried to cancel the the delay, now it is simple: Destroy(transform.GetComponent()); Destroy(gameObject);

It still happened.

alt text

and here is the error log.

try.png (24.6 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mr0menphis · May 26, 2017 at 12:56 PM

you destroy the children and try to play the particle system after, so basicly you try to play something, that has been destroyed. I am new to unity, but it looks like that to me, the same problem would occur in the TANKS! tutorial, they are handling it there. go to the TANKS! tutorial and check the 5th or 6th lesson, they handle that problem there, by unchilding the object and giving the Destroy() function the lifetime of the particles as delay parameter hope i could help :)

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

How do i destroy a character and have a particle effect after? 3 Answers

Particle System not tilting with parent object, it's still straight. 0 Answers

Playing particle on 1 instance of cloned prefab 0 Answers

How do I get a texture2D snapshot from a single rendered GameObject/SpriteRender/MeshRender in a scene? 0 Answers

How to destory any object that collides with a particle in a particle system?? 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