# AddMergedCollisionFromLayer

### Introduction

AddMergedCollisionFromLayer adds rectangles to the calling TileShapeCollection for all layers in the argument layer which have properties matching the predicate. Rather than creating individual rectangles for each tile, the created rectangles will be *merged* - all adjacent rectangles in either a row or column will be combined into one to reduce memory consumption and to speed up collision calls. AddMergedCollisionFromLayer is similar to [AddMergedCollisionFromTilesWithProperty](/flatredball/tiled-plugin/glue-gluevault-component-pages-tile-graphics-plugin-tileshapecollection/addmergedcollisionfromtileswithproperty.md), but it provides more control over how collisions are created. Note that [AddMergedCollisionFromTilesWithProperty](/flatredball/tiled-plugin/glue-gluevault-component-pages-tile-graphics-plugin-tileshapecollection/addmergedcollisionfromtileswithproperty.md) is simpler and may provide enough flexibility for many games.

### Code Example

The following shows how to add collisions for any tile which has a property IsSpike with a value of true.

```lang:c#
myShapecollection.AddCollisionFrom(CurrentTileMap, LayerInCurrentTileMap, 
    (list => list.Any(item => item.Name == "IsSpike" && item.Value == "true")));
```

Note that in this case the Name is the name of the property and the Value is the value of the property. The code above could be modified to check any property or desired value.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/tiled-plugin/glue-gluevault-component-pages-tile-graphics-plugin-tileshapecollection/addmergedcollisionfromlayer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
