Search Unity

Particle system playing but not emitting any particles.

Discussion in 'Scripting' started by deciduous, Dec 20, 2018.

  1. deciduous

    deciduous

    Joined:
    Aug 24, 2014
    Posts:
    4
    So I have a very strange issue. In my game I have players with particle systems that emit as they move and use the ribbon function in order to simulate a trail (using this method over trail renderer so I can tap into particle collision events). There is also screen wrap in the game for the player characters, and in order to get this work without drawing a ribbon between opposite ends of the screen on a player's wrap I unparent the current particle system on the initial side of the screen, set it to destroy when it's finished, and instantiate a new one parented to the player on the other side of the screen. The strange bit is that, under certain conditions, the newly instantiated system will not emit any particles. Here is a list of features of this issue that confound me:

    -If I pause the game and restart it, or if I highlight anything in the hierarchy, the particle system begins emitting like normal until I wrap again. Sometimes the particle system just works too. It's not always broken.

    -This only occurs when I wrap from the bottom of the screen, and if I instead jump to the top and wrap it will instantiate a system that works fine.

    -The newly instantiate particle system is playing and is in the correct position, but when the game is paused and it's highlighted it shows that 0 particles are being emitted even though the emission module's rate over distance is set to 10. If I log the particle systems states it says it's playing and emitting even when no particles are being emitted.

    I've tried several hacky solution attempts including setting the particle system prefab inactive and setting it active in code, setting the system to NOT play on awake then telling it to play once instantiated, etc, but none of them works whatsoever.

    Here is the code for the particle instantiation:
    Code (CSharp):
    1.  //this function checks to see if the player should wrap and calls the wrap funtion
    2. private void CheckForWrap()
    3.      {
    4.          if(transform.position.x < leftConstraint)
    5.          {
    6.              TriggerWrap();
    7.              transform.position = new Vector3(rightConstraint, transform.position.y, 0f);
    8.          }
    9.          else if (transform.position.x > rightConstraint)
    10.          {
    11.              TriggerWrap();
    12.              transform.position = new Vector3(leftConstraint, transform.position.y, 0f);
    13.          }
    14.          else if (transform.position.y > topConstraint)
    15.          {
    16.              TriggerWrap();
    17.              transform.position = new Vector3(transform.position.x, bottomConstraint, 0f);
    18.          }
    19.          else if(transform.position.y < bottomConstraint)
    20.          {
    21.              TriggerWrap();
    22.              transform.position = new Vector3(transform.position.x, topConstraint, 0f);
    23.          }
    24.      }
    25. //this function runs in the character controller when a screen wrap is detected
    26. public override void TriggerWrap()
    27.      {
    28.          currentTrail.transform.parent = null;
    29.          var main = currentTrail.GetComponent<ParticleSystem>().main;
    30.          main.loop = false;
    31.          main.stopAction = ParticleSystemStopAction.Destroy;
    32.          currentTrail = Instantiate(trailPrefab, trailSlot.transform.position, Quaternion.identity, trailSlot.transform);
    33.          currentTrail.GetComponent<PlayerTrail>().AttachToPlayer(this);
    34.      }
    Here is the code that is attached to the particle system and run when a new prefab is instantiated from the character controller:
    Code (CSharp):
    1. //this is the function that is called when a new particle system is instantiated
    2.      public void AttachToPlayer(PlayerController pc)
    3.          {
    4.              player = pc;
    5.              ParticleSystem.CollisionModule collisionModule = trailParticleSystem.collision;
    6.    
    7.              LayerMask layer0 = 1 << LayerMask.NameToLayer("Player0");
    8.              LayerMask layer1 = 1 << LayerMask.NameToLayer("Player1");
    9.              LayerMask layer2 = 1 << LayerMask.NameToLayer("Player2");
    10.              LayerMask layer3 = 1 << LayerMask.NameToLayer("Player3");
    11.    
    12.              switch (player.GetID())
    13.              {
    14.                  case 0:
    15.                      collisionModule.collidesWith = layer1 | layer2 | layer3;
    16.                      break;
    17.                  case 1:
    18.                      collisionModule.collidesWith = layer0 | layer2 | layer3;
    19.                      break;
    20.                  case 2:
    21.                      collisionModule.collidesWith = layer0 | layer1 | layer3;
    22.                      break;
    23.                  case 3:
    24.                      collisionModule.collidesWith = layer0 | layer1 | layer2;
    25.                      break;
    26.                  default:
    27.                      break;
    28.              }
    29.          }
    Here is a screenshot of the particle system prefab that is used:

    PlayerTrail.PNG

    Any help would be appreciated!
     
  2. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    We also have a recreation of this on Unity 2018.3. Particle system says it is playing and emitting but the particle count is zero. The problem happens when we transform the camera position in our case. We can fix it by transforming the camera position again and magically the particles appear. I strongly suspect a unity bug here.
    We can also make the particles appear by clicking in the project heirarchy in scene view.
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Consider submitting a bug report with a minimum repro project
     
  4. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    We will do so through our unity support contract - it's just we have bigger bugs to solve first.
     
  5. changko

    changko

    Joined:
    Mar 20, 2018
    Posts:
    1
    set culling mode to 'Always Simulate' .

    I've had the same problem and was puzzled why the particle count was always zero even though isPlaying was true.

    My theory is that when i start my game, the ParticleSystem is off camera, and the Automatic culling doesn't simulate the particles, even though it is playing. This would also explain why it starts simulating properly when you go to Scene view. Clicking it in the heirarchy then resets it, while it is on camera in the scene view.
     
    austinborden, kuailemario and catfink like this.
  6. catfink

    catfink

    Joined:
    May 23, 2015
    Posts:
    176
    thanks I'll try this