I’m currently developing a mobile game and I ran into a small problem. When my player first collides with an enemy, the game freezes for a bit.
The weird thing is that this happens only when first time OnTriggerenter2D is called. Enemies that collide with my player afterwards do not cause any lag.
I profiled the game and it shows that three things cause this issue, specifically:
Physics2D.CompileContactCallbacks, Physics2D.SendContactcallbacks and Physics2D.SendTriggerContactCallbacks.
My player has a dynamic rigidbody2D attached as well as BoxCollider2D that has set OnTrigger to true.
The same applies to the enemies, except the rigidbody2D is set to kinematic.
Here’s a screenshot from the profiler: https://i.imgur.com/RDVHeXg.png
I’m testing it on Samsung S4 mini.
Any ideas how to fix this?