# CustomActivity

### Introduction

CustomActivity is a function which is part of every Screen and Entity. This is where you can place code that you would like to run every-frame. Examples of common logic in CustomActivity include:

* Collision
* Input
* Checking for non-UI events such as a timer ending a level

CustomActivity is called by default by generated code, so it should never be called in custom code.

### Order of CustomActivity

A Screen's CustomActivity will always be called last relative to the Objects inside of it. More generally speaking, the children Objects of a Screen or Entity will have their CustomActivity called before the parent container. Objects in a Screen or Entity will have their CustomActivity called in the order in which they appear in Glue. In this example, the order of CustomActivity will be as follows:

1. SubEntityInstance
2. SubEntityInstance2
3. SubEntityInstance3
4. TestEntity
5. Whatever contains TestEntity (like a Screen)

![SampleHierarchy.PNG](/files/XzfVQ4NzXASQ5PvoP3dH)


---

# 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/glue-runtime-api/glue-reference-code-customactivity.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.
