Profiler Physics2D.FindNewContacts lag spike after resuming game

So I am doing a tile based game like Terraria, and I have this lag problem.

Every time I resume my game (Time.timeScale = 0f to Time.timeScale = 1f), there is a noticeable lag spike, and the Profiler shows that Physics2D.FindNewContacts is the reason behind that:

I have all my physics running in FixedUpdate(), and all the colliders I have are in the player (CapsuleCollider2D and CircleCollider2D) and in every solid tile (BoxCollider2D)

Any clues of what could be generating that lag after resuming the game?

Depends what you’re doing while its “paused”. The above is called when either a new collider and its shapes are created or an existing collider and its shapes are changed. Both these flag that new contacts need to be calculated.

The fact that you change the time-scale won’t do anything to physics.

With that amount of time, there has to be an astounding number of shapes. Sounds like you’re doing something super inefficient by maybe having crazy numbers of colliders and it’s not scaling well but all we know is the info you provided so not much to go on TBH.

You can look at shape/contact count in the profiler here to; it’s not just about looking at total time.

1 Like

That’s the info I needed to know.

I had a refreshing chunk function on Update() for activating and deactivating the tiles (gameObjects with a collider) that are far away, but I don’t need to check that if the game is paused. With a simple ‘if game not paused’ there the problem is now solved.

Thanks!!

Last thing, for future reference, how I look at the shape/contact count in the profiler? Never used this tool until today.
Thanks in advance.

1 Like

There’s a Physics 2D area in the profiler. Select that and its one of the metrics shown.