# 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="/files/JedMG5CpA0x3ztHGTyTh" 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: 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/gum/code/gum-code-reference/graphicaluielement/children.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.
