> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/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/gum/code/gum-code-reference/graphicaluielement/children.md).

# Children

## Introduction

The Children collection contains the direct descend children of the GraphicalUiElement. An instance's children will report the instance as their parent.

Note that Screen GraphicalUiElements have `null` for Children. The reason is because Screen GraphicalUiElements do not have a position or size - they are merely containers for children without providing any layout information. Therefore, to access the items that a Screen contains, see the `ContainedElements` property.

## Children in Gum

If a GraphicalUiElement is loaded in a game project, its Children property contains the direct children as established in Gum.

For example, consider a component with six children named ColoredRectangleInstance, ColoredRectangleInstance1, ... , ColoredRectangleInstance5:

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-78bc4a9bf0f6b17cbd0bdac6450b15e20127b449%2Fimage.png?alt=media" alt=""><figcaption><p>ExampleComponent with six stacked children</p></figcaption></figure>

If using code generation, these could be accessed by their names. If not using code generation, or if you need to access each item by index, then the component's Children property provides access.

For example, the following code could be used to set the children width:

```csharp
// Initialize
for(int i = 0; i < ExampleComponentInstance.Children.Count; i++)
{
    var child = (GraphicalUiElement)ExampleComponentInstance.Children[i];
    child.Width = 100;
}
```

Of course, if you know the type of the children, you can cast the child to its specific type. Be careful doing this, as you may end up with an invalid cast exception.

For example, the following code could be used to edit the children as ColoredRectangleRuntimes:

```csharp
// Initialize
for(int i = 0; i < ExampleComponentInstance.Children.Count; i++)
{
    var child = (ColoredRectangleRuntime)ExampleComponentInstance.Children[i];
    // change any property that is specific to ColoredRectangleRuntime
}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/gum-code-reference/graphicaluielement/children.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
