Moving Colliders giving me Physics.simulate spikes in Profiler

Hi there,

i’m currently prototyping a mobile game and i’m a bit stuck because of some performance issues. The thing is: I have a somehow “grid” of cubes (16x16), which are moving every now and then (usually each 5 seconds). They all need to have a collider/Trigger on, because i need to Raycast against each one of them.

Problem is: If i’m moving them by script (setting transform.position), i get ugly lags, caused by Physics.simulate (so says profiler). If i remove the collider everything is smooth, but i really need to Raycast against them… I don’t need physics for anything else than the Raycasts, so no rigidbodys or whatever involved. Already tried to increase fixed Time, lowered physics solver iteraton count and all the other Physics settings - with no success.

Any Ideas how to solve this?

If I remember of Physics rules :

  • If you move object with collider by script it can generate high lags cause an object with a collider must stay static.
  • If you want move the object by script you must give it a rigidbody an define it as kinematic. Then if you want move it during an update, you must move it in fixedUpdate and not in Update.
  • As advice, yo ucan watch the video named “Unite 2012 - Performance Optimization Tips and Tricks for Unity” at this link : and watch between 21.30 and 25.00 roughly. All your answers are here :wink:

If you need the colliders just as raycast hit object do this:

  • Make sure they are set to isTrigger
  • Create a new layer for the objects and put them all on this layer
  • Go to Edit → project settings → Physics and disable all interactions in the collision matrix. So just clear the row and column of your layer in the matrix.
  • When raycasting against them make sure you use the layermask and pass a layermask that only contains the layers you want to raycast against.