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

Question Why does my game stutter when I first enable a few point lights in the scene?

Discussion in 'Editor & General Support' started by DrakeClausen, Sep 18, 2022.

  1. DrakeClausen

    DrakeClausen

    Joined:
    Apr 24, 2022
    Posts:
    7
    In my game I am using a particle system for a flamethrower. On the very first time the particle system is enabled, and only on the very first time it is enabled, the game stutters for a split second. Additionally, this only happens in the WebGL build, and does not happen when playing the game in the editor. Any ideas on why this happens and/or how to fix it? Thanks!

    UPDATE - After some troubleshooting I determined that the issue is not with the particle system but rather is with some point lights that are enabled when the flamethrower is used. Any ideas on why this happens and/or how to fix it?
     
    Last edited: Oct 3, 2022
  2. evyatron

    evyatron

    Joined:
    Jul 20, 2014
    Posts:
    132
    One clue might be that it doesn't happen when you go back to the menu and then start a new game, or even when you refresh the page - which makes me suspect it's loading something too big/complicated into memory (usually massive textures or sound).
    I don't have any experience with WebGL, but you can:
    1. Check the audio import settings - usually turning on Load In Background really helps.
    2. Check what your particle system is loading - is it using a billboard or a mesh? What textures is it using, and how big are they?
    3. Deep Profile this in the Editor. you might not see the FPS drop, but you should still see something registering.
    4. You can check the Memory Profiler if you want, and compare a before and after snapshots to see everything that's being loaded.
     
  3. DrakeClausen

    DrakeClausen

    Joined:
    Apr 24, 2022
    Posts:
    7
    Thank you @evyatron ! I did some troubleshooting and determined that the issue is with the point lights that are enabled with the flamethrower. I set it up so that some point lights are enabled when the flamethrower is used to provide the effect of the fire illuminating the scene. I did this because I thought enabling and disabling 3-5 point lights would be less resource intensive than using the light component on the particle system. Again, this only happens when the lights are first enabled. Any ideas on why this happens and/or how to fix it? Thanks!
     
    Last edited: Sep 19, 2022
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    When you first start up your game, run a one-time benchmark that enables/disables the problem lights, ideally behind a loading screen. This pre-warms your lights and prevents them from stuttering in-game.

    My guess is that something in the render pipeline is having to be loaded or compiled the first time the lights are enabled.
     
  5. DrakeClausen

    DrakeClausen

    Joined:
    Apr 24, 2022
    Posts:
    7
    Thank you very much @Madgvox , your solution worked!
     
    Madgvox likes this.