Search code examples
c#unity-game-enginegame-physics

getting really bad prefomace issue in unity when trying to move more then 1000 rigidbodies in the scene


I have an object build from aprox. 1700 small cube meshes (pretty simple ones). if there are been hit i'm trying to return it to the origin a few seconds after any other objects hits it (the trigger is any other collision). the result is between very poor performance to complety stuck.

what i tried to do so far :

  • limit the object to one collision trigger to avoid activation over and over again .
  • disable the object physics
  • move the object using both Physics and the transform directly.

what seems to be the problem ? can unity even handle that much objects and collisions ?


Solution

  • The problem is that Physics in Unity is not a native solution. Unity uses PhysX for physics, and but of them are used like a black box so Unity doesn't know how it works under the hood. That's why all physics-based operations are complex and have rather bad performance. 1000 physics-based objects seems to much to handle by Unity3d. And it's not the only limit in Unity, for example if you create about 10 000 gameobjects (no matter which functionality they will have) they can freeze even Unity's editor.

    As for a possible solution there's not much you can do:

    • Look through optimization guides and best practises here, here and here.
    • Use Unity's profiler to optimize Physics performance (try to remove physics-based "spikes")
    • Try to develop some system which will disable gameobject's which are not seen on scene in current moment.
    • Try to simplify the meshes and collider. Or try to make 1 big mesh which will split into smaller parts when you need interaction.
    • Try to create your own simple mathematically-based physic. I know it will be really complicated but your not universal physical solutions may have much better performance rather than PhysX.

    So anyway it will be a difficult struggle.