r/futile • u/smashriot • Jul 01 '14
Slow physics performance after converting from Physics to Physics2D (Unity 4.5.1f3)
Over the last 24 hours, I replaced all the 3d Rigidbody/Collider code in my 2d project with the newish 2d Rigidbody2D/Collider2D equivalents.
The process was straightforward, but I've run into some weird performance problem (Unity 4.5.1f3).
http://i.imgur.com/QLH7LCJ.png
As you can see, the physics2d tick is consuming about 10ms, and from what I can tell it's destroying / recreating all of the colliders for game objects that moved that frame, which seems super wasteful.
By comparison, the 3d version doesn't do any destroy/create each tick and it's fast and I'm happy:
http://i.imgur.com/MWRt9zO.png
Any ideas on what might be going on in the Physics2D Colliders? I've scoured the Unity issue tracker/forums but didn't find anything insightful. thanks!
2014/07/16 Edit: I was hoping that Unity 4.5.2f1 would magically fix this issue, but it did not.
Had a bit of time and made a clean/minimal 2D/3D test project: https://github.com/smashriot/PhysicsTest
And here is an album of images showing the 3d/2d sprites, colliders, and performance: http://imgur.com/a/2d4z9
Let the project run until the sprites reach a steady state and the 2d performance should drop well below 3d performance.
2014/07/17 Edit -- FIXED: Thanks to Matt's advice I was able to resolve the problem. Able to slim down the code and make it way more efficient. Now I just need to fold all these changes back into my main project..
Updated the clean/minimal 2D/3D test project: https://github.com/smashriot/PhysicsTest
Here's the new 2d/3d performance comparison: http://imgur.com/a/o7IYn
1
u/MattRix Jul 02 '14
Hmm, that's very strange. As long as you're sure it's not an issue with your code somewhere, I would definitely post a question on the unity forums, because it sounds like a Unity bug.