- Home /
RigidBody causes heavy performance issues
Hi,
We have a test scene with over 1000 game objects, no rigidbodies or colliders attached, all of which have certain movement patterns and are handled exclusively by script.
Just by adding the ridigbody component to the game objects (kinematic set to true, gravity set to false and velocity/angular drags set to infinity; no colliders attached) has a massive impact on performance. Physics.simulate jumps from 15ms to 200ms on a dual core PC, as seen in the profiler.
What is unity doing at that point that takes up so much CPU power? Isn't there a way to tell unity to completely ignore a rigidbody without having to destroy it?
Unfortunately we need the rigidbody component on our objects because we want to be able to enable physics when specific circumstances are met.
Untested idea, put your objects to sleep:
https://docs.unity3d.com/Documentation/Components/RigidbodySleeping.html
That does sound like a Unity bug. There's no reason for it. Even looking at robertbu's link, the first thing Unity says is that you can have tons of rigid bodies in your scene if they are sleeping. If they are disabled (technically), I would think the same applies. Although the parameters are set to 0/infinity, etc, they are probably still used to do calculations. $$anonymous$$y personal workaround attempt would be to disable the rigidbodies on startup (or in the editor), and only enable them when you need to use them. (i.e. set the .enabled flag).
We already tried putting rigidbody.Sleep() in fixedUpdate() and Debug.Log(rigidbody.isSleeping()) in Update().
We found out that while the object was moving the rigidbody would remain awoken (even while using Sleep() in fixedUpdate()) and only sleep when the object would remain still.
Playing around with sleep velocities in the project settings did not help at all, it rather made things even worse when we tried to greatly increase those values.
And last, as in Unity 4.3, there is no .enabled flag in the rigidbody component unfortunately.. (https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.html)
Thanks for your comments, we remain a bit frustrated here..
Debug.Log(rigidbody.isSleeping())
^ This will kill your framerate. Debug.Log() is very slow!
I think you also only need to tell a rigid body to sleep once.
to be more specific we used:
if(!rigidbody.isSleeping()) Debug.Log(...);
On the other hand this was only to test if the rigidbody eventually goes to sleep, which it apparently doesn't. :)
Answer by RetepTrun · May 23, 2014 at 02:53 PM
my 2c
1 If they are stationary in the beguinning put them to sleep in awake() before physics can do anything.
2 Or leave off the rigidbody and add it later in game.
3 Lower the amount of physics iterations (forget exactly what it called but theres a setting that makes physics calculated less often)
4 Drags at infinity sounds bad to me for some reason. I would try more like 0.
Hi,
When they are stationary they manage to sleep. However, they awake when the transform is changed, which gives us a headache.
That is what we have implemented at the moment but it is not efficient at all.
Do you mean the fixed time option?
Infinite Drag means infinity friction. We do not want objects to fly around the map. :)
Thanks for your comments!
Your answer
Follow this Question
Related Questions
Fixed Update Time, Object Stop moving 0 Answers
Can I add a rigidbody to the parents instead of every object? 2 Answers
Are my kinematic rigidbodies slowing my scene down? 2 Answers
Raycaste vs trigger Colliders & Rigidbody performance 1 Answer
Is there anyway to optimize my physics based game? 3 Answers