Search Unity

ParticleSystem.SetParticles kills trails with "Die with Particles" disabled

Discussion in 'General Graphics' started by yasirkula, Oct 27, 2019.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Hi,

    I'm modifying my particles using GetParticles/SetParticles in a script. My particles have Trails module enabled and its "Die with Particles" property is set to false. It works fine on Unity 5.6 and 2017.2 but on 2018.4 and 2019.1, my trails do die with the particles. I've narrowed down the issue to the
    SetParticles
    call. If I call it, my trails whose particles have died will be killed instantly (even though "Die with Particles" is disabled). The preview screen shows the number of alive particles as ~60 on 2017.2 but this number is ~30 on 2018.4.

    To reproduce the issue:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ParticlesIssue : MonoBehaviour
    4. {
    5.     private ParticleSystem particles;
    6.  
    7.     private void Awake()
    8.     {
    9.         particles = GetComponent<ParticleSystem>();
    10.     }
    11.  
    12.     private void Update()
    13.     {
    14.         // Creating an array in Update is inefficient but this is for testing purposes only
    15.         ParticleSystem.Particle[] arr = new ParticleSystem.Particle[particles.particleCount];
    16.         int aliveParticles = particles.GetParticles( arr );
    17.         particles.SetParticles( arr, aliveParticles );
    18.     }
    19. }
    At runtime, trails behave correctly when the script is disabled but they start disappearing immediately when it is enabled.

    I can open an issue but I am looking for a workaround for current Unity versions, if possible.

    Any feedback is welcome.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    I think it is caused by a bugfix to prevent old trails from hanging around when using SetParticles (because we don’t get/set the trail data, we don’t know whether to reset it or preserve it when using SetParticles.)

    You can report an issue and we will look at it, but I suspect that is something that will only get fixed by a new feature to allow the trail data to also be get/set. (I.e. not a fix that can be applied to already released versions)
     
    yasirkula likes this.
  3. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    This still seems to be an issue in 2020.3 - did anyone report this?
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I don't remember reporting this. I guess I was too busy with work at that time that I've forgotten about this.
     
    AndrewRH likes this.
  5. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    From a quick test, it seems that if you use the newer C# particle job system to set the position, then the trails don't die when the particle dies :) YAY!
     
    Last edited: Feb 18, 2022
    yasirkula likes this.
  6. michalpiatek

    michalpiatek

    Joined:
    Feb 26, 2021
    Posts:
    81
    Defy still a bug in 2021.2.10 with standard get/set method. I'll report it later this week.
     
  7. michalpiatek

    michalpiatek

    Joined:
    Feb 26, 2021
    Posts:
    81