Rigibody and FixedUpdate

I have a case where I am adding multiple rigid bodies and taking a performance hit that accumulates as it goes through the for loop:

for (int i = 0; i < objCount; i++) { ... gameObject.AddComponent(typeof(Rigidbody)); ... }

The method is called from onGUI(). My goal is to get all iterations running with no slowdown. Will FixedUpdate have any impact here even I am not modifying the rigidbodys directly? does it even make sense to use it in this case, and if so, how?

(This is the first time I trying to use FixedUpdate, and fairly new to Unity 3D)

Thanks hg111

use the generic version of AddComponent() to avoid the performance hit of boxing and unboxing. That will help.

Update runs every frame...roughly...which is why you have to use Time.deltaTime or calculate an elapsed time yourself.FixedUpdate runs at fixed designated intervals--a fixed time step, which is highly desireable for physics calculations. The performance cost of the tasks you are performing won't change if you place them in Update or FixedUpdate or a regular function. It is still the same workload. Ideally you want to place heavy tasks in Start or Awake. See if you can add your components there. Maybe you can add them ahead of time and simply enable them in an update or a function.