Search Unity

Tips for game performance

Discussion in 'Editor & General Support' started by Shears, Nov 25, 2015.

  1. Shears

    Shears

    Joined:
    Jul 7, 2015
    Posts:
    24
    What are some good tips for improving the all around performance of a game without dropping the quality settings?

    Any and all tips are helpful! I'm sure a lot of people will like to know any tricks out there. Thanks
     
  2. Kamilche_

    Kamilche_

    Joined:
    Jan 11, 2015
    Posts:
    75
    The main thing I've found, is even a SMALL amount of debug statements is enough to make your game crawl, especially when in an update routine. Create a single variable called 'debug', and check that variable before you write output to the debug window. That way you can keep all your debug lines intact, but just inactivate them when you need to test speed, or do a release.

    I've found that dynamically drawing to a Texture2D makes my game stutter. I modified it so it only does it once a sec, and then it stuttered once a second. I had been using that technique to avoid the 'neon glowing letters' problem when using native Unity text, which doesn't react correctly to lighting or shadow. I finally ditched text altogether and display 3d meshes of letters in the scene. Now it's speedy, AND reacts correctly to environment lighting.

    At this point, my game has picked up speed and suffers no more on any platform.

    In short - beware debug.log statements, and modifying graphics in memory, they slow things down quite a bit.
     
  3. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,252
    If you have a large 3D scene with lots of meshes, it can be beneficial to stop rendering stuff you can't see or is almost out of view. We put objects into three layers - in the example below layer 13 and 14 plus the default layer which uses the farClipPlane for the particular camera. It is a pretty quick way of improving the frame rate. In one game we dropped our frame render time by 50% just by applying this simple technique - we have a LOT of verts in our scene...
    Code (CSharp):
    1.                 Camera _p1Cam = Player1Camera.GetComponentInChildren<Camera>();
    2.                 if (_p1Cam != null)
    3.                 {
    4.                     _p1Cam.farClipPlane = _farClipPlane;
    5.                     float[] _cullDistances = new float[32];
    6.                     _cullDistances[13] = _smallObjCullDist;
    7.                     _cullDistances[14] = _mediumObjCullDist;
    8.                     _p1Cam.layerCullDistances = _cullDistances;
    9.                 }
     
  4. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,905
    Have you used the Profiler?