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

Game lags so much when running the Build the 1st time, but smooth from 2nd time onwards

Discussion in 'Editor & General Support' started by Rekize, Oct 31, 2018.

  1. Rekize

    Rekize

    Joined:
    Apr 15, 2017
    Posts:
    5
    Hello, this is my first Unity forum post

    My game has a certain UI feature that can run smoothly in the Editor. When built and run the .exe for the first time, the game lags very much when that feature comes up for the first time. But strangely, when the feature come up for the second time onward, or when I restart the game, or quit game then run the .exe again, the feature can come up smoothly without lag.

    An issue may be related is that the Build also takes long time to load on first run, but load significantly faster from 2nd time onward.

    Anyone has ideas of what is going on and how to solve this? Thank you very much for any help.
     
    Last edited: Oct 31, 2018
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    My first guess would be that your computer has a low amount of RAM and you're experiencing memory contents being swapped to virtual memory on disk, which would be even worse if your virtual memory is on an HDD instead of an SSD.

    Beyond that, you should take a look at what the profiler says is going on.
     
  3. Rekize

    Rekize

    Joined:
    Apr 15, 2017
    Posts:
    5
    I have 16GB physical RAM, though old DDR3 but should be more than enough I think?

    Profiler is a good idea, let me try.
     
    Last edited: Nov 1, 2018
  4. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    In Project Settings --> Player there is a setting near the bottom called 'Pre-loaded Assets'. Drag any laggy assets into those fields and it should clear up. Keep in mind this is probably just a quick fix. I recommend you find the true source of the lag or it will just come back later.
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It is more than enough if you don't have a lot of other applications running that are using it all up.