# InsertCollidables

### Introduction

InsertCollidables allows the adding of a list of ICollidable rectangles to a ShapeCollection. This is usually done for collidables which align with a grid and which are used for solid or platformer collision.

### Conceptual Explanation

Often when creating solid collisions, a game uses the [TileShapeCollection type](https://github.com/flatredball/FlatRedBallDocs/blob/main/documentation/tools/tiled-plugin/glue-gluevault-component-pages-tile-graphics-plugin-tileshapecollection.md). However, at times each collision rectangle should be an entity. This is necessary if the collision has additional behavior beyond collision. For example blocks may play animations, may trigger game actions (such as unlocking a door), or may HP and break (such as when being shot). In situations like these, each block should be an entity to keep track of its state and to provide additional functionality through custom code. TileShapeCollections automatically adjust their contained rectangle RepositionDirections, but collidable lists do not have this functionality built-in. Prior to adjusting reposition directions, a row of blocks may have the following RepositionDirections:

![](/files/BnpzypH0uIdhjzLLtER6)

The purple reposition directions are considered undesirable because they can cause snagging. After fixing this problem using InsertCollidables, the RepositionDirections will only point outward, allowing other entities to collide without snagging.

![](/files/6GwKN05N7RQHcltsBF3P)

### Example - Adding Blocks to a ShapeCollection

This example uses a collidable entity named **Block** which has a list called **BlockList** in **GameScreen**.

![](/files/6JPqMbmUQ9AvvXDjSXe1)

We will use an empty TileShapeCollection to fix the RepositionDirections:

1. Add a new **TileShapeCollection** to the **GameScreen** called **CombinedTileShapeCollection**. The name CombinedTileShapeCollection is a recommended name for TileShapeCollections used specifically for fixing RepositionDirections. ![](/files/sv02qLferUhhk9dgY7Vu)
2. Leave the newly-created TileShapeCollection as empty. ![](/files/7eFR8nMrvVgrr0SbVDIS)
3. In code, call **InsertCollidables** on the CombinedTileShapeCollection to add the BlockList

```
CombinedTileShapeCollection.InsertCollidables(BlockList);
```

Now all blocks in the BlockList will have their RepositionDirections adjusted for every Block that is already created when the method is called.


---

# 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/insertcollidables.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.
