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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

my game lags after i build it but smooth when in editor

Discussion in 'Editor & General Support' started by asiangamemaker, Oct 3, 2016.

  1. asiangamemaker

    asiangamemaker

    Joined:
    May 17, 2015
    Posts:
    25
    Hello everyone. I'm currently having an issue i dont have any idea why. First of all, my game has a lot of trees and buildings. i tested in my editor and i got like 80FPS while walking around. but when i build and run it, i got like 15 fps straight away. i tried disabling my scripts but there are no improvements. i used lightmaps, ambience occlusion but no improvement in fps. Hope to get some help here :)

    Below is my game preview screenshot.

    My specs :

    I7-6700HQ
    Nvidia GTX960m
    16GB DDR4 prob 1.png prob 3.jpg prob 5.jpg prob 2.jpg prob 4.jpg
     
  2. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    Try using the profiler in the editor, it will show you whats slowing your game down. I suspect its the trees, maybe use more LOD, texture atlasing, ect.?

    A side note: it looks really cool, what kind of game are you making?
     
  3. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884

    That's the first thing I thought as well, BUT - he said it's smooth in the Editor.
    So not sure if that's going to help too much.
     
  4. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    Yes, but it should still show whats eating up the resources.
     
  5. asiangamemaker

    asiangamemaker

    Joined:
    May 17, 2015
    Posts:
    25
    thanks my friend. I'm currently making a medieval type of game. interact with ai and follow stories, do mission and gain money, not only do mission, perhaps you can farm, own a house and a pet like horse, pig etc.. but that will be future maybe. as for now, need to sort out the village done. Everything you see here is all freewre from the assets store. Working alone on this :)

    Btw, this is my profiler
    profiler.jpg
     
  6. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    The overview (scroll down a bit) and the CPU usage (scroll up a bit) are what you should look at, generally these have the culprits. Also, what's your draw calls in the scene?
     
  7. asiangamemaker

    asiangamemaker

    Joined:
    May 17, 2015
    Posts:
    25
    Here you go..
    profiler 3.jpg profiler 1.jpg profiler 2.jpg
     
  8. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    It's pretty simple, you could just read it yourself. Then let us know the possible culprits.

    It looks like it's the rendering. What are you draw culls? (Click the rendering, then look down in the description box).
     
  9. asiangamemaker

    asiangamemaker

    Joined:
    May 17, 2015
    Posts:
    25
    I have little background on this game development btw. Thanks for helping me out :)

    Draw calls is between 2K to 4K.
     
  10. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,433
    Maybe your game view window is much smaller in the Editor than in the build? If so the build might be slower since there are more pixels to render. Also try disabling vsync. That might further affect the frame rate in the build.
     
  11. asiangamemaker

    asiangamemaker

    Joined:
    May 17, 2015
    Posts:
    25
    how do i disable the vsync?
     
  12. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    Yeah, no problem, I just figured its easier for you if you tell me the stuff that looks craziest, as there are alot of panels in the profiler and it could be a pain to upload all the images.

    Yep, thats most likely the problem, it could definitely be a bottleneck. Just for some perspective a mobile game is normally under 160, so 2k-4k is quite a bit more. Take a look at this, it has some references that should help you understand and reduce the amount of draw culls. Now this all depends on your graphics card (and that of your target audience) but you should be able to get it sub 500 without too much hassle.
     
    theANMATOR2b likes this.
  13. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,433
    When you google "unity how do i disable the vsync" it's the first result.


    To reduce drawcalls check this:
    https://docs.unity3d.com/Manual/DrawCallBatching.html

    And learn about light baking and deferred vs forward rendering, and see if you can build a lighting/rendering setup that performs better. It's not an easy to answer question as the topic is quite deep and we don't know all the details of your project. E.g. if the houses are made up of dozens of individual objects with 3 different materials each, not set to static, and you have many dynamic light sources, that could be a big part of the problem.
     
    Ryiah and RavenOfCode like this.
  14. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    What is the build... desktop, web, mobile, TV? Didn't notice any info on this. If someone already asked and I missed it sorry about that. If it is working awesome in the editor and not on the target build that makes me think possibly you are targeting web or mobile or something else besides desktop.

    Also keep in mind you really can't go by what the FPS shows in the Editor. If that is all you are going by then disregard it. If you are saying the game truly lags (you can see the lag, feel the lag) that is different.
     
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    You're using the profiler wrong. You shouldn't profile the editor - attach the profiler to the built game.
     
  16. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    This may be an obvious question, but is it perchance on a higher quality setting when you run the build?
     
  17. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    You could also check to see if "anti-aliasing" is the culprit in your quality settings. Lots of times in my games, anti-aliasing is terrible for performance, especially with a lot of trees. I'm just guessing though, and trying to put some ideas out there. Profiling your built-game is probably the only way to see exactly what it is though.
     
  18. ali12000

    ali12000

    Joined:
    Sep 26, 2022
    Posts:
    2
    When you leave build mode, click save and it should go away. Doing this has always worked for me.