- Home /
The question is answered, right answer was accepted
Advice for perfomance and efficency
I wonder if experienced game developers give advices in respect of the topic. I.e. the most common newbee's mistakes that have negative impact on game perfomance. Especially for 2D games, 2D physics and sprites.
Bit of a discussion question that might be better on the forum.
$$anonymous$$y short list:
Not attaching rigid bodies to things that move.
Using slow find functions every frame.
Using functions that allocate memory every frame (and hence hit Garbage Collection) - this includes foreach loops
Long loops of NPCs testing for distance to things for their AI (try not to do it, spread it over multiple frames, use sqr distance, build a smarter data structure)
Using lots of thick raycasts or overlapping areas every frame
Is there a simple and efficient way to do something not each frame but skipping some?
Yep - do heavy operations in a coroutine, calculate a bit and then yield.
Could you give an example of using coroutine for this purpose. I use coroutines but not sure that in the best way. Tnx
Something like this:
IEnumerator UpdateEnemyAI() {
while(true) {
for(var i = 0; i < enemyList.Count; i++) {
enemyList[i].CalculateGoals(); //example
//other processing
if( i % 10 == 0 ) yield return null;
}
}
}
Answer by ankush_Kushwaha · Feb 28, 2014 at 01:10 PM
1) Try to minimise Draw-calls , poly-counts and material.
2) Use Atlas to combine textures and materials.
3) Use combined meshes instead of using different mesh for objects.
Check this.
Follow this Question
Related Questions
Fastest primitive collider 1 Answer
Syncing data from client to server in 5.1 networking 1 Answer
Temporary disable collision, what's best performance-wise 1 Answer
Physics Casting Performance 1 Answer
Improve Script Performance Physics 2 Answers