- Home /
Programmatically added rigidbodies not active
Hi,
I am playing around with programmatically adding gameobjects with rigidbodies connected together with joints.
The problem I am having is that the bodies seem to not always be calculated when the simulation begins, they just stay in place until I perform some kind of user interaction with them which will enable physics calculation again for those objects affected.
I have tried to initialize the objects so that the rigidbodies would be added as active physics objects:
foreach (var line in layerLines)
{
var lineCollider = line.GetComponent<Collider>();
lineCollider.enabled = true;
var lineRigidbody = line.GetComponent<Rigidbody>();
lineRigidbody.useGravity = true;
lineRigidbody.sleepThreshold = 0;
lineRigidbody.WakeUp();
}
But I only started to get some repeatable startup behavior when I initialized the objects by adding a small force to them:
lineRigidbody.AddForce(new Vector3(0.00000001f, 0, 0));
I would really like to avoid adding this force to the objects, can there be some better root cause for why these bodies are not always simulated from the start?
Your answer
