- Home /
How to efficiently populate scene with GameObjects
I'm creating a 2D scene for the first time and want to make sure I'm setting the scene up properly.
For the background, I have many building assets which are just GameObjects with only SpriteRenderers attached. I also have window, door, etc prefabs that only have SpriteRenderers and a collider. If I add all of these, my scene will end up with 40+ GameObjects.
Am I approaching this the right way? And if not, how can I populate my scene efficiently?
Answer by JonPQ · Sep 25, 2017 at 10:17 PM
40 is not a lot of game objects. For 2D there are a few things to (mainly) worry about....
Overdraw... are you re- drawing a large percentage of the screen by layering sprites on top of each other.... avoid this where possible.
transparency, are you using alot of transparent sprites (with alpha channel) ? only use where necessary as alpha is slow... (but bear in mind the size of sprite... alpha on some small sprites doesn't matter alot... but on large areas, it matters more)
Draw calls. open up the statistics button at the top... try to keep your number of draw calls / batches low. ballpark <100 but the lower the better, especially on mobile. You can optimize this by using Sprite sheets (unity can automatically batch them together for you onto the same sheet) look it up in unity docs. Typically you get one or more draw calls per material.
There is a lot of info around on performance, just google it or look in unity docs or forums on previous posts.
Appreciate it. And what is considered a reasonable number of draw calls / batches?
Its more about... are you wasting draw calls... there is wasted performance overhead with each draw call.... setting up rendering hardware... Suppose you are drawing 100 zombies, each one is a sprite... they could all be using different animation frames.... and that could be 100 textures => 100 materials. OR is you put the same packing tag name on them all, unity might be able to pack them all onto one sprite sheet. = 1 texture = 1 material. and then it can send them all to the rendering hardware in 1 go (1 batch) :) basically you'll be wanting to organize things to $$anonymous$$imize draw calls, and allow unity to batch more objects together. https://docs.unity3d.com/$$anonymous$$anual/DrawCallBatching.html
couple other tips... make sure backdrop is non transparent.... non lit. set camera to clear z depth only.... no point in clearing backdrop, then putting a backdrop on top also.
Your answer
Follow this Question
Related Questions
Weird line on top of a single sprite 0 Answers
How to change sprite only on click or during shoot state? 1 Answer
Texturing custom 2d sprite 0 Answers
How change sprite animation texture?? 2 Answers
Cut holes in sprite using other sprites 2 Answers