Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Optimizing my game

Discussion in 'Scripting' started by mmangual_83, Apr 17, 2014.

  1. mmangual_83

    mmangual_83

    Joined:
    Nov 14, 2013
    Posts:
    8
    In my game I am having an issue with my performance. But let me back up a little and explain where my issue comes from.

    It's like this: My game has 10 scenes (for now, its a long demo!); Each scene is laid out like this:

    Scene
    3d room
    Up to three cameras and each with their own SSAO and Bloom components
    Room Lighting
    3d Object that moves (using iTween)
    I also have an FPS counter to better illustrate performance. But the thing is that, according to my FPS counter, it shows that my scene runs at 15 (at maximum) FPS and each of my scenes are very simplistic and should at least run at 60+ FPS (at minimum). I went online to research what might the issues be and I found very useful tips like:

    making each of my scene's room be static,
    using light-mapping
    writing up a script that enables the Bloom and SSAO effect for the active camera and disabling the unused cameras.
    But this only caused my FPS to go up by only 2 or 3. And I also clicked on statistic in the Game window and the odd thing is that Unity's FPS show that my game is running at 60, 70 and even 89 FPS but my in-game FPS says that my game is running at 15, 17 OR 19 FPS.

    Of course, I have done this testing in my executable and it is still runs at 15 FPS so I do not know why it is still doing this.

    What I want to know is,could it be because of my many scenes scenes? While running one scene, could Unity be rendering all of my scenes in the background at the same time? Or an even broader question: what other improvements have I missed that will help improve my FPS?

    Thank you for your time and many more thanks in advance!
     
  2. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    Disable the unused cameras, don't disable their effects.
     
  3. mmangual_83

    mmangual_83

    Joined:
    Nov 14, 2013
    Posts:
    8
    I did but it still does not improve the FPS
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Use the profiler. Otherwise you're just guessing.
     
  5. mmangual_83

    mmangual_83

    Joined:
    Nov 14, 2013
    Posts:
    8
    I have a question, is there a way to access the player settings programatically? Mainly, I want to set a boolean value for the Static Batching and Dynamic Batching.
     
  6. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    That doesn't happen.
     
  7. mmangual_83

    mmangual_83

    Joined:
    Nov 14, 2013
    Posts:
    8
    Okay, thank you. What about accessing the static batching feature found in Player setting? I need to access it programmatically.
     
  8. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Like KelsoMRK suggests, figure out what's causing the performance issue first. Don't worry about static batching, post-processing effects, or anything like that yet. You can't productively optimize until you know what you need to optimize.
     
  9. Deleted User

    Deleted User

    Guest

    Also a good tip which I've learned the hard way a few days ago : Get rid of all Debug.Log calls. I've spent about an hour staring at the code and wondering why my single scene with 20 sprites was running on 17 fps. Turns out I've left 4 Debug.Log calls in the OnGUI code I was working on before.

    But maybe it's just me being an idiot. Q_Q
     
  10. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    Just to check, are you sure your in-game FPS script works correctly?
     
  11. mmangual_83

    mmangual_83

    Joined:
    Nov 14, 2013
    Posts:
    8
    Yes the script runs correctly
     
  12. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    Thats really weird because debug.log calls take up basically no processing power... if they are demining the performance of the game that much, there is a problem with your code somewhere... And it needs to be optimised. Try optimising all the code you can throughout your whole project, this can greatly improve performace in some cases :)
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723

    Not really.

    Debug log will happily ruin any computer. They take up a lot of time, due to the unity editor overhead. Especially if you're flooding the editor with several per frame.
     
  14. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    Wow I have never had this problem, I usually run several debug.log calls simultaneously in infinite loop functions and I have never had a performance issue with it :confused:
    I guess it would vary greatly depending on the specs of the computer it is running on.

    At least I know now for future :)
     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'm running a 4770k at 4.6ghz and it will still bog down. Depends how many you're doing per frame but it's certainly been an ongoing issue with unity.
     
  16. egoquat

    egoquat

    Joined:
    Jul 4, 2012
    Posts:
    93
    In my experienced, I always to check performance profiler (CPU usage, GPU usage, Memory usage) on unity3d first and then find function to top overheads.
    I think you should to know on where comes from delay or which functions leads to delayed and why...
    Srry my native is not english so not good but i wish this will be helpful to you.

    -- ref --
    https://docs.unity3d.com/Documentation/Manual/Profiler.html

    -- ref --
    http://robotduck.wordpress.com/2011/08/05/code-optimization-in-unity-part-2/
    --> Kinds of like this custom profiler always helpful on my projects performance optimizations.