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. Dismiss Notice

Can you tell me professional steps of optimisation

Discussion in 'General Discussion' started by mfatihbarut, Jan 6, 2021.

  1. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    Hi all,
    The optimization stages of my game in my mind is
    - Using some kind of mesh baker to reduce tris count.
    - Learn and use lighting/shadow optimization
    - Maybe deleting some options like vertical sync from the player settings (but not sure which to do)
    But not sure what to do more and even how to do these.
    Is there any professionally build list to optimize my game?
     
  2. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Joe-Censored likes this.
  4. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    useful thanks
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    1) Make game build
    2) Check profiler against build
    3) Optimize whatever is taking more time than expected or acceptable
    4) Return to step 1
     
    Antypodish and SparrowGS like this.
  6. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    You always want to use the profiler. One-size-fits-all performance rules do not always apply to every scene. Sometimes they may even make your performance worse. The profiler can help indicate what the actual problems are and whether your optimizations are actually improving your performance or not.
     
    Joe-Censored likes this.
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I highly recommend starting from the top and working your way down. Optimise your game design before you optimise your code. Its generally better to throw out a system you don't need entirely rather than to try and eke out performance from it.
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    Well, the general steps are:
    1. Measure
    2. Modify
    3. Test
    4. Repeat

    Exactly what you're measuring, modifying and testing depends on the project and the issues you're running into, and how you do it is in turn dependent on that. The Profiler is a good general purpose tool if you're working in Unity which will help with a lot of this.

    On the programming side of things another good tool in C# is System.Diagnostics.Stopwatch. This lets you take detailed timings from inside a function, so you can see what parts of that function are actually taking up the time.

    It could also be worth getting to know the other tools in Unity's "Analysis" menu, depending on where things are slow.
     
    EternalAmbiguity and bobisgod234 like this.
  9. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,644
    Dont know if your game is 3d, or 2d, or goal platform. But in the 3d world, this is a section of my "Unity Bible", notes on what i do to optimize your assets before hand:

    ====OPTIMIZATION====
    --All assets should have LODS, and adjusted correctly.
    -Adjusting the far/near clipping planes on the camera.
    -Increase the pixel error. This results in more significant height-popping of terrain subsections.
    -Increase the detail distance (the distance that grass and detail meshes are visible).
    -Decrease the tree distance (the distance beyond which trees aren't drawn at all).
    -Decrease the billboard start (the distance at which tree meshes are replaced with billboards).
    -Reduce the Max Mesh Trees (the maximum number of trees which are displayed as meshes at any one time any others will be displayed as billboards regardless of their proximity).
    -Remove reflection probes.
    -Use texture atlas's.
    -If Minimap: use texture/screenshot of the world instead of camera, if possible.
    -Bake occlusion culling.
    -Reduce models polygons/tris.
    -Bake lightmaps, static/baked lightmaps.
    -Delete parts of models not needed.
    -Reduce number of textures per model.
    -Take off shadows on objects not needed.
    -Scale down textures, if needed - 2048 for high detail, 1024 for mid detail, 512 for low detail, etc.
    -Directional light - should be yellow-ish tint.
    -Color Space: linear.
    -Ambient light (if used): blue tint
    -Adjust light intensity.
    -Chunk/split up terrain and stream terrain tiles, if large/open world senarios.
    Texture Import Settings:
    Gen Mipmaps: true
    Max Size: 1024
    Compression: low quality (Lower Disc Size)
    Max Size: minimum
    Atlas textures
    Remove Alpha Channel
    Disable: Read/Write Enabled
    16bit Over 32bit color
    Disable Mipmaps for UI
    Disable Streaming Mipmaps On: decal projector textures, refection probs textures, terrain textures
    Mesh Import Settings:
    Mesh Compression: use agressive compression
    Disable: read/write enabled
    Rig: if not using animation, disable Rig
    Blendshapes: disable if not using
    Normals And Tangents: if material is not using, disable

    That should give you a direction...
     
    tmonestudio likes this.
  10. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    680
    Profiling and responding to actual problems is the key.

    Lots of great tips in this thread, but I also want to warn against unnecessary overuse of LOD meshes, which can actually be detrimental to performance and the maintenance of a project. More LODs isn't always a good thing (in a world with GPU instancing and such like).

    @jbooth wrote a very informative post on this subject last year, so it's worth keeping in mind the other side of it as well, so you strike the right balance.
     
  11. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,875
    The key is to profile and only optimize what is necessary. Doing optimisations for things that are not needed is often a waste of time. You could spend ages optimising your scripts, only to find that they only use 2%, whilst that time could have been spent optimising what is actually taking up the most.

    So profile, use the profiler, memory profiler and frame debugger to track down actual problems and then react accordingly.
     
  12. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    If you are somewhat competent programmer more than 95 procent of frametime will be spent in unity domain not your domain and 95 of that will be spent rendering the game.

    Problem with unity is that they dont make games them self so tooling is none existing sadly. For example analysing lightmaps etc
     
  13. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    That depends on what you're doing. If you're processing thousands of agents in a background simulation...maybe not.
     
  14. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Most games let the players optimise the game for their hardware via video settings.
    • You can achieve similar results to mesh baking by enabling instancing in the material shader (it allows the GPU to copy repeating objects in the scene faster and easier).
      • Using camera occlusion and baked occlusion also reduces what the game renders but you need separate meshes for this to work best.
      • However this works against combining meshes which reduces draw calls a good GPU optimisation.
    • I would not remove Vsync just make it an option.
    • Ditto for shadow settings.

    Distance fog and camera range can massively speed up your game and add atmosphere.

    These are basic steps you should be building into your game, however as people have stated you need to run the profiler often to see if anything you are adding to the game is slowing things down.

    It is often easy in Unity to write slow code that utilises 'FindSomething' functions every frame in Unity or just runs every frame in Update/FixedUpdate* when it is not needed, the profiler (deep mode) should help you find these hot spots in your code.

    *FixedUpdate can be even worse as it runs at the speed of the physics engine which occurs multiple times per graphics frame.
     
  15. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    Offcourse there are edge cases, but in general you will spend your time optimizing not the code but the other aspects
     
  16. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Sure. Just pointing out that it's not an absolute rule and isn't necessarily about how competent a programmer one is.
     
  17. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Also the default Unity pattern of code per a game object (GO) is really bad when you have lots of GOs of the same type as every GO is using up precious time just calling it's update function and pulling it's variables into the CPU cache.

    A manager script that cycles through lots of specific types of GOs (via an array of structs) can be a lot faster and is a step towards other optimisations like 'multi-threading' and DOTS.

    For Example:
    Imagine a game with Zombies where every zombie looks and listens for players before moving towards them.
    The default Update() per a GO would be overwhelmed very quickly with proximity tests (Sphere casts, Raycasts).

    Whereas a manager class could quickly work out where the groups of zombies are then run single tests based on the the centre of those groups.

     
    tmonestudio and SparrowGS like this.
  18. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Another potential performance problem is the Instanciation/Destory mechanic in Unity. For a lot of destructible game objects you are better off with a pooling system that disables then recycles and enables game objects.

    This cuts down on processing power and memory utilisation issues such as garbage collection (which is renowned in Unity for causing performance hiccups during gameplay).
     
    Last edited: Jan 8, 2021
    tmonestudio and SparrowGS like this.
  19. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
  20. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I can't upvote this enough, I keep the amount of active monobehaviors as low as possible, usually i end up with around 5.
    This saves so much performance it's actually ridiculous.

    also if you have something that runs huge loops and inside the loop there's function calls it also costs time, if the call is to a simple calculation it is a lot better to just do the calculation inside the loop instead of calling a function to calculate.
    I tested this with a gravity simulation on a solar system scale, and if I calculate the force needed each fixed step inside the loop instead of calling that calculation in a separate function I can increase the amount of bodies a lot.
    this was back on unity 5.6 or maybe 2017.1.
     
  21. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    great thanks
     
    warthos3399 likes this.
  22. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    You can use Aggressive Inlining for some inner loop functions to keep your code cleaner and faster.
     
    SparrowGS and MadeFromPolygons like this.
  23. MDADigital

    MDADigital

    Joined:
    Apr 18, 2020
    Posts:
    2,198
    I would say bother with inlining attributes are microptimization 9 out of 10 times.
     
    angrypenguin likes this.
  24. mfatihbarut

    mfatihbarut

    Joined:
    Apr 11, 2018
    Posts:
    1,058
    I ll consider thanks.