Unity Physics2D recreate each collider when changing a transform.

Hello there.

While I was looking to enhance the performance of my game, I saw something disturbing with the FixedUpdate stuff.

I need to move my objects each FixedUpdate to gain a better precision over what I’m doing, and in the profiler, it is translated as this :

If you look at the expanding under Gameboard.FixedUpdate(), it is quite explicit.

In my FixedUpdate, I directly change the position of my game object. And each time I do this, Unity destroy all colliders and recreate them at the new position, and with or without rigidbody attached.

The only way to avoid this process of destruction and creation, with cause a huge performance drop, is to have a rigidbody attached and change its velocity.

So, intended behaviour?
Some other way to move a gameobject without risk?

I bump this, it cause me a lot of modifications on my scripts I’d really like to avoid. :s

Hi, did you find a solution, because we are having the same problem. It’s costing us nearly 100ms / frame when built for iOS.

Thanks,

BPF

same here

Hey,

Well, the only solution I found is :

  • You must not move a collider without its Rigidbody.
  • You must not move a collider, with or without a rigidbody, from the FixedUpdate function.
    Do either of those two and your collider will be destroyed and recreated to its new position by Box2D. :frowning:

same here, we had a freeze on ios and android because the re-genetation crash for one 2d collider (bad triangles?) and only on mobile… take us long to figure out. I would like know the reason behind this perf issue: destroy all colliders and recreate it at runtime.

for us, the fix will be to remove all 2d physic component of our game, since we only use it to make 2d raycast, instead we will make an in house raycast solution.

Well, a simple solution is to ensure every collider or group of collider have a rigidbody attached to it and do the transform through the rigidbody’s gameobject.

Just never move a collider alone. As it is seen as a static collider by box2D, it will be deleted and recreated somewhere else.

Oh my, this is quite a gotcha! This has been causing me serious issues!

Meet The same problem…Any good method to fixed this? this is a big hole in develop 2D game on mobile…

Ridgidbody.MovePosition should take are of it.

It doesn’t, I’m running into the same perf glitch despite using MovePosition because the rotations are 3D,

3108391--234897--upload_2017-6-14_22-47-20.png which

Internally Box2D seems to move the collider anchors position and rebuild the collider profile with the unpleasant result of 2ms for only 300 colliders.

It’s a shame because Box is super fast when doing purely 2D rotation, the documentation should reflect that it’s ill suited for 2.5D games where rotation is in non Z axis.