Search Unity

Making a game object "Static". When should that be done?

Discussion in 'Getting Started' started by Sparticus, Apr 21, 2021.

  1. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Hey all,

    I have a game where everything in the game is dynamically placed with code. Nothing is added to the scene before the game is loaded.

    The code first creates a tilemap of all the ground tiles. Then added in objects around the scene (like trees, rocks, etc). Once all those trees and rocks have been dynamically placed I use a combine mesh script that combines them all into a single mesh for performance. Enemies are placed into the scene dynamically (which only move around and rotate, no scaling or animations). There are bullets that are shot at the enemies, etc

    All the above items are prefabs.

    My question is, I have set none of these items to be "static". Should I be doing that? All the tutorials I ever see are based on someone prebuilding a background scene and marking them as static since they will always be the same. I'm not sure if what I am building would benefit from making static. I think when I select the box I see no difference (in draw calls or performance)

    Btw, I have a big texture atlas for most of the items above so even when the scene is quite busy with enemies, bullets, trees, rocks, etc... I only have around 15 draw calls.

    Thanks for any advice you can give.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    The page on static objects has more information than I can provide here, as it's not as simple an answer as you might think.

    If you're generating the terrain items at runtime and merging them into a single mesh, I'm not sure you gain anything by marking it static. And since your enemies move, they don't qualify as static objects, and may benefit from dynamic batching (that happens without you having to do anything). Which is probably why you don't notice any change in your draw calls when you toggle it on.

    Are you having performance issues at this point? If not, I wouldn't be worrying about this yet. Wait until you start noticing issues before bothering with optimization.
     
  3. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Ya, no performance issues at this point. I'm just trying to make sure as I learn Unity I do things in the best manner.

    Thanks for the info :)
     
    Schneider21 likes this.
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Hey, when you get that all figured out, let me know and I'll get you hired at my company. There's about 12 of us professional Unity developers and not a day goes by we don't break some sort of "best practice" rule in an effort to meet our deadline. :p
     
    Ryiah and stain2319 like this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,203
    Good luck with that. What's best is not always the same. I just had to increase the precision of shadows in a project because while the lower precision brought higher performance there were a few cases where it would occasionally cause flickering to occur. I'm not even positive that was the culprit as much as a workaround.