- Home /
Many units, best performance practices
Currently I am having a huge frame drop when I get about 300-400 units, What is the best practice to maintain a large amount of units (possibly 5000 and up is my target) in a simple top down RTS, according to the profiler the the biggest chunk of spent memory is in Physics2D.FixedUpdate and Unit.FixedUpdate
My units all have a RigidBody2D as well a circleCollider2D to handle collisions as well as not have them clump in together. but whenever I move them (the code inside FixedUpdate) my framerate goes to hell, any tips?
My game does have alot of times when units will be clumped together while moving through small choke points.
The following is what I assume is the main culprit, either the way I move the units, or the physics controlling them, the profiler states 60% towards unit.fixedupdate and 35% for physics2d.fixedupdate
void FixedUpdate ()
{
if (Moving) {
tForm.position = Vector3.MoveTowards (tForm.position, PointB, this.Velocity * Time.deltaTime);
}
}
I went ahead and published your question since someone might have a magic bullet, but in general design/discussion questions should be asked on Unity Forums. The format of Unity Answers is for single, specific technical questions.
Answer by AironeneroTechnologies · Nov 23, 2014 at 05:29 PM
You are using the unity standard navmesh pathfinding? Is really slow. Use a oyur custom algoritmh applied in a coroutine, that procedurally calculates the path step to step and not in 1 time. Also use of crowd movement to simplify calculation will help a lot.
In short: instead to make each unity calculate in only a short time all the path calculate in more steps for a group of units the path, this is the secret of massive RTS games like planetary annihilation or Supreme commander.
$$anonymous$$aybe I should have included my fixed update code to be more clear, all my fixedupdate does is move the unit, I updated my question with the code in question, so I guess I should rephrase it, how to properly move my unit? because I feel that it is either that or something involving physics.