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 /
  • Help Room /
avatar image
0
Question by Steveo22 · Nov 18, 2016 at 08:15 AM · parentparticle systemparticle emitter

Particles vanishing after setting parent to null. Any Fix?

Hey there,

First time ever logging into the website, I hope this is the right place to put this question. For background, I'm an intermediate Unity user, I've been using it for about two years, and have been programming for about 3. Anyway, here's the problem:

I actually used the 2D engine for the first time yesterday, and I was messing around on it today. The problem occurs when I have a projectile (it's a net), which gets instantiated by the player script attatched to the player gameobject. Upon either colliding with a non-player object OR reaching the 3 second timer, the net projectile will self-destruct.

In order to spruce it up, I have a particle system attached to the net, with the intention of detaching it (clearing the parent) in the net's self-destructing function (named HitDestroy). About at the same time, I am calling ParticleSystem.Play() on the emitter, so that it will start playing at that point, since PlayOnAwake is false and looping is false and it hasn't otherwise been playing. The code looks like this for the Net class:

using UnityEngine; using System.Collections;

public class Net : MonoBehaviour {

  private Transform tf;
  public ParticleSystem part;
  [HideInInspector]
  public int direction = 0;
  private float speed = 0.1f;
  void Start () {
      tf = transform;
      StartCoroutine ("deathTimer");
      if (direction == 0) {
          tf.GetComponent<SpriteRenderer> ().flipX = true;
      }
  }
  void Update () {
      tf.Translate(new Vector3(((direction - 0.5f) * 2f) * speed,0f,0f));
  }
  private IEnumerator deathTimer(){
      yield return new WaitForSeconds (3);
      HitDestroy ();
  }
  void OnTriggerEnter2D(Collider2D other){
      if (other.gameObject.tag != "Player") {
          HitDestroy ();
      }
  }
  void HitDestroy(){
      part.Play ();
      part.transform.SetParent (null);
      Destroy (part.gameObject,2.1f);
      Destroy (gameObject);
  }

}

The problem seems to be occurring in HitDestroy, since all of the other code works just fine. When the particle system's transform has its parent set to null (either through SetParent or tf.parent = null), the particles vanish. According to the triangle count and GetParticles calls on the emitter, the particles do exist, they are being spawned. Strangely, though, they do not appear. I've checked everything i could think of, and I've been at it for a good 3 hours. Scoured official and unofficial forums extensively, still can find nothing. Since it's 2D, i've tried adjusting sorting layer, order in sorting layer as well. I've ensured that the scale is not fudging up the system (its a pretty basic particle system).

I've attempted rearranging the lines in HitDestroy, figuring it might not be possible (for some reason) to call Play after detaching the GameObject that the particle system component is on.

I recognize that there are multiple ways to have a particle system spawn when an object needs to be destroyed/disabled. In all of the projects I play around with, I've done that using at least 3 different methods (like actual instantiation). The point of this is that I specifically want part.Play (); part.transform.SetParent (null); Destroy (part.gameObject,2.1f); to be called concisely and within a single function/method of the Net class. The reason I'm being relatively stubborn with this process is that, being a computer science major (and a crummy one at that) I want to learn exactly why this isn't working, and I'm pretty sure its just some amateurish error, but I would love for someone to demonstrate that.

Thanks for your time, hopefully my writing is legible enough, I haven't slept in a good 30 hours, which is probably why I'm having problems in the first place.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Steveo22 · Nov 18, 2016 at 08:42 AM

As a side note, this does not happen in the 3d engine.

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

79 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

Related Questions

Particle Effect to disable after it's played once 1 Answer

Particles not showing 0 Answers

Particle system does not follow emitter movement in world space: URP 1 Answer

OnParticleCollision() on parent script, for a child particle system? 2 Answers

How can you create non circular rocket flame particle effect? 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