# How to get a component from a ClassDefaultObject?

**URL:** <https://forums.unrealengine.com/t/how-to-get-a-component-from-a-classdefaultobject/383881>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [February 4, 2017, 1:17am UTC](https://forums.unrealengine.com/t/how-to-get-a-component-from-a-classdefaultobject/383881 "2017-02-04T01:17:42Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Ciberus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ciberus/32/561261_2.png) [@Ciberus](https://forums.unrealengine.com/u/Ciberus)\
**Post date:** [July 8, 2023, 1:13pm UTC](https://forums.unrealengine.com/t/how-to-get-a-component-from-a-classdefaultobject/383881/9 "2023-07-08T13:13:20Z")

</div>

Found solution on how to get all `ActorComponents`(both created in C++ and Blueprint) from another `ActorComponent`(non `SceneComponent`).

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/c/b0c10a86a9e220e252d5a59361833fd46fe91606.png)  
If you need to get ActorComponents from Actor itself replace `GetOuter()->GetClass()` on `GetOwner()->GetClass()`

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/c/e3c4056c0cbd4b53c8e21acf5fc2c37bafb735a6.png)

code example

```auto
static TArray<FString> GetHitRegistratorsNames(UObject* OwnerObject)
{
        TArray<FString> Result = {};

        UBlueprintGeneratedClass* BlueprintGeneratedClass = Cast<UBlueprintGeneratedClass>(OwnerObject);
        if (!BlueprintGeneratedClass) return Result;
        
        TArray<UObject*> DefaultObjectSubobjects;
        BlueprintGeneratedClass->GetDefaultObjectSubobjects(DefaultObjectSubobjects);

        // Search for ActorComponents created from C++
        for (UObject* DefaultSubObject : DefaultObjectSubobjects)
        {
            if (DefaultSubObject->IsA(UCapsuleHitRegistrator::StaticClass()))
            {
                Result.Add(DefaultSubObject->GetName());
            }
        }
        
        // Search for ActorComponents created in Blueprint
        for (USCS_Node* Node : BlueprintGeneratedClass->SimpleConstructionScript->GetAllNodes())
        {
            if (Node->ComponentClass->IsChildOf(UCapsuleHitRegistrator::StaticClass()))
            {
                Result.Add(Node->GetVariableName().ToString());
            }
        }
        
        return Result;
}

```

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-get-a-component-from-a-classdefaultobject/383881)._
