# TestCollision

### Introduction

TestCollision is a method which is automatically called by the FlatRedBall engine on all IWindow instances which are part of the GuiManager . The Gum plugin automatically writes code for every Gum runtime to implement the IWindow interface, and Gum objects are directly or indirectly added to the GuiManager automatically. In other words, the TestCollision method is usually not called in game code, but can be used to diagnose problems with UI events not being raised.

### Debugging TestCollision

TestCollision is part of the GumRuntime.IWindow\.cs file, which is added to all projects which use Gum. Therefore, this can be easily debugged by calling the method and stepping in to see the logic flow. IWindow instances are either directly added to the GuiManager (if it's the root) or indirectly added as a child of a root object. The FlatRedBall code does not directly call TestCollision on all living UI elements. Rather, it calls it on the top-level, which is then responsible for calling it on its children. Therefore, when testing TestCollision, it's best to begin the test at the top level UI element (ignoring the Screen itself). For example, consider the following image:

![](/files/fUnmA6ZgxgTVTUi0UoYp)

In this case the top-level object is **ChildStandardContainerInstance**. If testing collision against **ButtonInstance**, then TestCollision should be called on **ChildStandardContainerInstance** to simulate the engine's behavior. To access the ChildStandardContainerInstance at runtime:

1. Drag+drop the Gum screen file (.gusx) onto the Glue Screen's Objects
2. Use the **Source Name** dropdown to select the desired object (ChildStandardContainerInstance in this case)
3. Click OK

<figure><img src="/files/7psEw4Mb8hGJWCtU4NsN" alt=""><figcaption></figcaption></figure>

To follow the logic:

1. Open Visual Studio
2. Open the Glue screen file which contains the newly-added object (GameScreen.cs in this case)
3. Find the CustomActivity method
4. Add the following code:

```lang:c#
void CustomActivity(bool firstTimeCalled)
{
    var cursor = GuiManager.Cursor;

    if(cursor.PrimaryClick)
    {
        ChildStandardContainerInstance.TestCollision(cursor);
    }
}
```

Now we can add a breakpoint to the TestCollision call. Notice that the call is wrapped in an if statement. This gives you the chance to position the cursor where you want it before hitting the breakpoint. Without the if statement, the breakpoint would hit immediately, making debugging more difficult.

![](/files/beXz4n2yZAweYCVpIBee)


---

# 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/api/gum-runtime-api/gum-wireframe-graphicaluielement/testcollision.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.
