Can you set physics material on a tile-by-tile basis

I’m working on a game that uses tilemaps extensively alongside 2D physics.

We’re currently using CompositeCollider2D as well as Tilemap Collider 2D to handle collision. And we set a physics material on the RigidBody2D assigned to the GameObject with the Tilemap component.

But this limits us to one physics material per tilemap. I was wondering if it’s somehow possible to set a physics material on a tile-by-tile basis.

For instance, if we have a set of tiles for an ice level that has both icy tiles and non-icy tiles and I want to change the friction for those specific tiles so they’re not the same across a tilemap where they’re placed.

Is this possible? I know collision takes into account physics materials before OnCollisionEnter happens, so certainly I can’t do this by programmatically altering the physics material in that method.

Anyone have any clever (or obvious) solutions for this or do we need to have a separate tilemap per physics material?

I don’t believe you can no. Will need a separate tilemap.

1 Like

You only need the collision info, not the material. It would be nice to automatically adjust the behaviour but you can also do so in your code with a little more extra work.

Just needs a check for the ground tile and what that tile’s type is, then change some values the character controller works with based on the tile type.

You wouldn’t get per-tile physics anyway in this situation, the composite takes the shapes from tiles and merges them all into different shapes such as edges or polygons.

Historically Unity has always only supported a single material per-collider but we’ll be changing that in a future version of 2D physics. That said, if you use something like the composite, as I said, the shape no longer represents a specific tile but a whole domain of them.

1 Like

Ah, sorry @MelvMay, I didn’t explain that very well. I meant that, currently, the only way we know to have separate physics materials is to also have a separate tilemap and composite collider per physics material.

Is there a performant alternative to doing it this way you suggest? Or is this the best way to go about it at this point?