Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

iOS Particle System: Short lag when spawning it for the first time.

Discussion in 'iOS and tvOS' started by andererandre, Apr 18, 2013.

  1. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    681
    Hello,

    I'm using a particle system that spawns 20 mesh particles (cubes) at once and throws them all over the place. When I spawn it for the first time I get a fairly huge spike lag - however, all spawns after this first initial one do not cause any lags (even if I spawn 3-4 of them simultaneously and I do not manually pool reuse the game objects at the moment). I guess Unity does some initialization of the particle system just-in-time when one is being spawned for the first time.

    My question is what is the best idea to prevent this from happening. One simple solution would be to spawn one of the particle systems right at startup, pushing the initial lag to the first frame that is being rendered. However, I'm interested in what's happening behind the scenes here and if there are better, less hacky approaches to fix it.

    EDIT: The initial lag appears to be proportional to the number one enters in "Max Particles" in the particle system, so it is probably caused because Unity allocates this particle buffer when a particle system (of that type?) is being spawned for the first time. The initial question remains, is it possible to pre-allocate this without spawning one right at the start?
     
    Last edited: Apr 18, 2013
  2. DeadlyAccurate

    DeadlyAccurate

    Joined:
    Apr 2, 2013
    Posts:
    181
  3. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
  4. penneyworth1

    penneyworth1

    Joined:
    Feb 7, 2015
    Posts:
    10
    Old question, but in case anyone else is struggling with this... I was having this issue, and it turned out to be caused by the fact that I was logging information with Debug.Log on instantiation of the particle system. I removed the logs, and the lag was gone.
     
unityunity