Quick answer: Call composite.GenerateGeometry() after tile changes. Or set Generation Type to Manual and explicitly regenerate after batch mutations.
A destructible wall is a Tilemap with TilemapCollider2D + CompositeCollider2D for perf. SetTile(coord, null) removes a tile visually; the merged composite shape still has the wall. Player can’t walk through the gap.
The Two-Component Pipeline
For Tilemap colliders:
- TilemapCollider2D: generates per-cell collision shapes from each tile’s collision polygon.
- CompositeCollider2D: merges those shapes into fewer, optimized shapes.
- Rigidbody2D (Static, with Used By Composite): required by composite.
Changes to the Tilemap should propagate down. Sometimes they don’t when SetTile is called from script outside the standard Tilemap workflow.
Force Regenerate
// After tile changes
tilemapCollider.ProcessTilemapChanges(); // 2022+ helper
composite.GenerateGeometry();
ProcessTilemapChanges flushes any pending edits in the TilemapCollider. GenerateGeometry then rebuilds the composite. Both required for reliable mid-frame updates.
Manual Generation Type
For bulk mutations, set the composite’s Generation Type to Manual:
// Inspector: CompositeCollider2D → Generation Type → Manual
void ClearLevelGeometry() {
foreach (var pos in tilesToClear) {
tilemap.SetTile(pos, null);
}
composite.GenerateGeometry(); // once after all changes
}
Manual mode skips automatic regeneration. You control when the (expensive) composite math runs. For 100+ tile changes per frame, this is a major perf win.
Inspector Settings
On the CompositeCollider2D component:
- Generation Type: Synchronous (auto on changes) or Manual.
- Geometry Type: Polygons (default) or Outlines (faster, edge-only).
- Vertex Distance: tolerance for vertex merging. Default 0.0005 is fine.
Verifying
Mutate tiles in Play mode. Toggle gizmos to see the composite’s polygon outline. After fix, the outline updates immediately to reflect tile changes. Test player collision against the new outline; should pass through cleared cells.
“Composite is a layer above TilemapCollider. Tile changes need to bubble up via GenerateGeometry — either auto with synchronous or explicit with manual.”
Set Generation Type = Manual for procedural levels — runtime tile generation has way better perf when you batch the regenerate.