# Walking Components

This page covers how to walk the Actor Components s in a 3D Level akin to the Details panel:

<figure><img src="/files/2Fg1cO0wkRP5Upmveh5u" alt="" width="368"><figcaption></figcaption></figure>

Compared to the Actor Hierarchy, Components appear deceptively simple to iterate over with a recursive function:

```python
def walk_component(component, indent=2):
    """walk the given component to print its hierarchy"""
    print(f"{' '*indent}{component.get_name()}")

    # recurse through any immediate children
    for child in component.get_children_components(False):
        walk_component(child, indent+2)
```

After getting our Actor reference, we can start from the <mark style="color:green;">root\_component</mark> reference:

```python
EditorActorSubsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)

selection = EditorActorSubsystem.get_selected_level_actors()
actor = selection[0] if selection else None

if actor:
    print(actor.get_actor_label())
    walk_component(actor.root_component)
```

If we compare the results of this function to the Details Panel, we'll notice quite a few extra lines:

<figure><img src="/files/C1uhWrpiUgZMueUDfqDu" alt="" width="563"><figcaption></figcaption></figure>

This is because the <mark style="color:green;">function\_test</mark> Blueprint Asset spawns child actors. If we only want to view the immediate components of our given actor we can add a [get\_owner()](https://docs.unrealengine.com/5.2/en-US/PythonAPI/class/ActorComponent.html#unreal.ActorComponent.get_owner) check to confirm the component is directly managed by the given actor:

```python
def walk_component(component, owner=None, indent=2):
    """walk the given component to print its hierarchy"""
    if not component:
        return
    
    # validate the component's owner
    if not owner:
        owner = component.get_owner()
    if component.get_owner() != owner:
        return
    
    print(f"{' '*indent}{component.get_name()}")

    # recurse through any immediate children
    for child in component.get_children_components(False):
        walk_component(child, owner , indent+2)
```

This added step gives us a printout that better matches the Details Panel:

<figure><img src="/files/inGnYcL09D8G1IrwwtZ2" alt="" width="518"><figcaption></figcaption></figure>


---

# 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://bkortbus.gitbook.io/unreal-python-recipe-book/actors/walking-components.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.
