Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Particle system not showing any particles but playing

Discussion in 'Scripting' started by DarkMoon21, May 11, 2023.

  1. DarkMoon21

    DarkMoon21

    Joined:
    Jul 26, 2021
    Posts:
    15
    I'm trying to make an healing area, and I decided to use particles to make it. When the player throws a potion, the particles starts where it crashed. To initialize them, I use this code, attached to the potion:

    Code (CSharp):
    1. private void OnTriggerEnter2D(Collider2D collision)
    2.     {
    3.         // Destroy if it doesn't touch the player
    4.         if (collision.tag != "Player" && collision != null)
    5.         {
    6.             Destroy(gameObject);
    7.         }
    8.  
    9.         // Make an healing area
    10.         if (collision.tag == "Ground" || collision.tag == "Platform")
    11.         {
    12.             Instantiate(particle, healingPotion.position, Quaternion.identity);
    13.         }
    14.     }
    Then, once it touches the ground, I use this code attached to a particles prefab to start emitting particles:

    Code (CSharp):
    1. if (!stopParticles)
    2.         {
    3.             particles.Play();
    4.  
    5.             Debug.Log("Playing particles");
    6.         }
    7.         else
    8.         {
    9.             particles.Stop();
    10.             StartCoroutine(DestroyGameObject());
    11.  
    12.             Debug.Log("Stoping particles");
    13.         }
    I use a couple coroutines to stop emitting the particles.

    The problem is that the code says the particles are emitting, but in the scene it says the particles count is zero. But once I select the particles in the heriarchy, I start seeing them and the count is not zero. Sometimes selecting them in the heriarchy doesn't work, tho, and I still don't see them.

    Any idea on how to solve this? Thanks in advance!
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    From some quick Googling, I noted that if you call
    Play 
    without checking if it's already playing, it will not show up correctly. You probably want to check
    isPlaying 
    before setting them to
    Play 
    or
    Stop
    .
     
  3. DarkMoon21

    DarkMoon21

    Joined:
    Jul 26, 2021
    Posts:
    15
    Thanks! I'll look into it.