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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

First Instantiation of Particle System Lags

Discussion in 'Editor & General Support' started by MWizard, May 17, 2019.

  1. MWizard

    MWizard

    Joined:
    Jan 5, 2017
    Posts:
    78
    I posted in scripting, but no one currently has given an answer. I figured I would reach out to another relevant section of the forum and share my pain. :)

    I have an extra simple Android app. The user taps the screen to destroy objects, and when an object is destroyed, it creates a particle system to give some feedback to the user that the object was destroyed (little tiny default particles). My problem is that when the first object is destroyed, and the first particle system is instantiated, there is a lag spike that locks up the game for about a 1/2 second. Every other destroyed object and instantiated particle system works smooth as silk.

    So I tried to pre-instantiate the object, as soon as the first object is destroyed, it still lags.

    I also tried to instantiate the object with the other game object that gets destroyed (they are both in their own parent object) and make the particle system not auto play. Sure enough, even if I did not play the particle system effect, it still freezes on that first object destruction.

    If I remove the instantiation from the object destruction, no lag. It seems to be tied to instantiating the first destroyed object. Again, at the end it all works fine after the first destroy/instantiate.

    I do not think an Object Pool is the answer here, only because pre-instantiating the object didn't help in two different scenarios.

    Thanks in advance for any help that is offered!
     
  2. W1zzel

    W1zzel

    Joined:
    Aug 7, 2017
    Posts:
    5
    Have you had any success? I am facing the same issue.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    I would pull out the profiler and see exactly what's causing the slowdown.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,198
    +1 to the suggestion to use the Profiler.

    Also pre instantiating doesn't mean it's fully prewarmed. You could try the broad sweeping Shader.WarmupAllShaders after your level is loaded to see if it helps. The more focused ShaderVariantCollection.WarmUp would likely be better to use though.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You could try instantiating and fully running the particle system out of camera view when the scene first loads as a brute force approach.
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,198
    For the shader prewarming, running them out of view wouldn't help. Running them in the camera frustrum but hidden behind something that doesn't cause them to get culled, such as e.g. a UI canvas with a loading screen, is how I used to brute force this before the prewarm functions existed.

    If it's not just the shaders, this brute force method might still yield some benefit though. But I'd start with the methods as it's more directed and requires less set-up.