2D Tilemap Collider eating up CPU, any advice??

I recently added a new section to my tilemap. It does have colliders on it, and I’m using the tilemap collider 2D.

It is absolutely destroying my CPU. Profiler says it’s a physics issue. If I turn off the new section, game plays fine.

I’ve identified the section in red here:
https://imgur.com/4CGdMDL

Here is the set up of the tilemap collider:
https://imgur.com/R1Ace6K

What can I do to reduce the amount of physics usage? It doesn’t seem like these tilemap colliders should be using as much juice as they are. It’s a very simple topdown 2D game. It’s just these static colliders that are eating my power.

Any advice here?

Anything moving that’s part of it? Anything animating?

Static Colliders in themselves don’t do anything so asking what you can do to reduce “the amount of physics usage” is impossible to answer. You need to find out what specific thing you’re doing to cause this then either reduce it or find another way. Pictures of the inspector and the gizmos won’t show this.

So showing the profiler results would at least help, rather than pictures of your game. Finding contacts, resolving contacts, you changing the colliders, modifying the Transform etc etc.

I see you’re using a CompositeCollider2D but do you know why you’re using that? So many devs add it “because they were told to”. If you add this and change it then it’s going to be expensive as it has to recalculate it all. Remove it if you don’t need it for any specific reason and you’re modifying the tilemap.

Why is the Rigidbody2D here Kinematic? Are you moving a complex collider like that? If not, make it Static!

Well this turned out to do it, I just changed all my kinematic colliders to static and that seemed to resolve the issues. Thank you! Sometimes you just need someone else to point out your dumbness.

Not dumb at all! The thing is, a Kinematic shouldn’t be more work if it wasn’t moving. I’d love to know what specific thing the profiler recorded that was taking a lot of time.

Anyway, glad it was resolved. Good luck with your project!

Well I’m back and you weren’t wrong. I ran into another issue which is changing my tilemap colliders to static only made it so bullets wouldn’t destroy on impact with the colliders.

Upon checking the profiler, I’m seeing issues under Physics2D.FindNewContacts at over 7000ms.

So something is obviously wrong. Based on my research I’m certain it has to do with the fact I’m using Colliders and/or Rigidbodies in the wrong way, but I’m just not sure how. It seems like it should be totally normal to have as many 2D colliders as I need without an issue.

Could you take a look at this image and let me know what you think I could be doing wrong? Could it be my use of composite collider?

No specific setting is going to cause FindNewContacts to take 7 seconds! It is simply going to be a lot of shapes overlapping a lot of other shapes. Contact count will be through the roof or at least potential contact count will be. This call is essentially inside Box2D itself; it’s one of many profiler entries we added to it so this exists inside the core engine itself. My point being that it’s just “doing too much of something”. :slight_smile: We just need to find out what that something is.

Can you strip-down the project into something you could package up and get to me so that I could just hit play without any interaction and just see it happen?

If you DM me on the forums with your email address, I can can set-up a private hosting session for you to upload it to. I’m on leave right now but I’m sure I can find an hour or two to investigate for you. Let me know.

Well thank you so much for this offer! I have also been on leave/ holiday. I’m back now, I’ll DM you my email now. Thank you for the support here!

1 Like

Came back here to post what ended up happening. Turned out that I needed to check into my collision matrix better.

Basically I had created a huge collider trigger to check whether a player was entering a new area of each map. As such that collider was interacting with a lot of different layers, including the tilemap which I left on default. So I created a new layer just for this area trigger, and then re-reviewed my default layer lane to see which layers really needed to interact with it.

This fully improved my fps. Shoutout to @MelvMay for the awesome help!

1 Like