> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/math/geometry/shapecollection.md).

# ShapeCollection

### Introduction

A ShapeCollection is a container that holds shapes of mixed types - [AxisAlignedRectangles](/flatredball/api/flatredball/math/geometry/axisalignedrectangle.md), [Circles](/flatredball/api/flatredball/math/geometry/circle.md), [Polygons](/flatredball/api/flatredball/math/geometry/polygon.md), [Lines](/flatredball/api/flatredball/math/geometry/line.md), AxisAlignedCubes, Capsule2Ds, and Spheres - and lets you treat them as a single unit.

That last part is the reason to use one. A regular list holds a single type, so a collision area made of a rectangle and two circles would otherwise mean separate lists and separate calls for each. A ShapeCollection lets you:

* Collide against every contained shape with one [CollideAgainst](/flatredball/api/flatredball/math/geometry/shapecollection/collideagainst.md) call, or push another object out of all of them with [CollideAgainstMove](/flatredball/api/flatredball/math/geometry/shapecollection/collideagainstmove.md)
* [Attach](/flatredball/api/flatredball/math/geometry/shapecollection/attachto.md) all shapes to a parent, so they follow an entity as it moves and rotates
* Show or hide all shapes at once through [Visible](/flatredball/api/flatredball/math/geometry/shapecollection/visible.md), which is useful when debugging collision
* Add or remove the whole group from the [ShapeManager](/flatredball/api/flatredball/math/geometry/shapemanager.md) in one call

Typical uses are collision areas built from more than one shape, level collision maps, and trigger regions such as doors, damage zones, and camera boundaries.

Most games do not create ShapeCollections directly. Entities marked as ICollidable get one named `Collision` automatically, and every shape added to the entity goes into it - see [Implements ICollidable](/flatredball/glue-reference/entities/glue-reference-implements-icollidable.md). A ShapeCollection can also be added as an object in the FlatRedBall Editor; see [the ShapeCollection object page](/flatredball/glue-reference/objects/object-types/glue-reference-shapecollection.md).

### Accessing Shapes

The ShapeCollection exposes its shapes through one list per type:

* AxisAlignedRectangles
* AxisAlignedCubes
* Capsule2Ds
* Circles
* Lines
* Polygons
* Spheres

Each is a PositionedObjectList and behaves like a regular list, so you can add to it, remove from it, and modify the shapes it holds:

```csharp
// Adding:
myShapeCollection.Circles.Add(someCircleInstance);

// Removing:
ShapeManager.Remove(myShapeCollection.AxisAlignedRectangles[0]);
```

To act on every shape of a given type, loop over the matching list:

```csharp
foreach(var circle in ShapeCollectionInstance.Circles)
{
    // do something with circle, like perform collision
}
```

A ShapeCollection has no single list containing every shape, so code that must touch all of them needs one loop per type.

### Adding a ShapeCollection to Managers

Shapes are drawn and updated only after they have been added to the [ShapeManager](/flatredball/api/flatredball/math/geometry/shapemanager.md). A ShapeCollection adds all of its shapes at once:

```csharp
shapeCollection.AddToManagers();
```

Removing works the same way:

```csharp
shapeCollection.RemoveFromManagers();
```

ShapeCollections created in the FlatRedBall Editor are added to managers by generated code, so these calls are only needed for collections created in custom code.

### Saving a ShapeCollection

Most games do not need to save ShapeCollections at runtime, but FlatRedBall can convert one to and from a serializable form. For more information, see the [ShapeCollectionSave page](/flatredball/api/flatredball/content/math/geometry/flatredball-content-math-shapecollectionsave.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/math/geometry/shapecollection.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
