# \[python\] Get Component from UBGC / UBlueprint

**URL:** <https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129>\
**Category:** Editor Scripting\
**Tags:** Python, unreal-engine, question\
**Created:** [September 10, 2019, 12:17pm UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129 "2019-09-10T12:17:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielOrchard](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/danielorchard/32/636987_2.png) [@DanielOrchard](https://forums.unrealengine.com/u/DanielOrchard)\
**Post date:** [September 10, 2019, 12:17pm UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129/1 "2019-09-10T12:17:59Z")

</div>

Im creating a new blueprint, and I want to change an element on a component inside it (a StaticMeshComponent). Im not sure how to get access to components from a CDO/BGC reference. Its not an actor so all the get components are out, this all exists only in the editor not in the level.

Right now as a workaround im setting a variable then in the construction script setting the component to use the variable, but it would be nice to learn how to access to component directly

```
 # Paths
path = childBP.get_path_name()
path_cdo = path + "_C"

# Objects - BlueprintGeneratedClass
bp_gc = ue.load_object(None, path_cdo) 
#Objects - BGC CDO
bp_cdo = ue.get_default_object(bp_gc)

#Set variable
bp_cdo.set_editor_property("MeshToUse", a)
```

---

<div class="post-metadata">

**Author:** ![DanielOrchard](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/danielorchard/32/636987_2.png) [@DanielOrchard](https://forums.unrealengine.com/u/DanielOrchard)\
**Post date:** [September 12, 2019, 12:12am UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129/2 "2019-09-12T00:12:57Z")

</div>

The question is still valid, but before anyone mentions this optimisation, iv switched the gc var setter to the much simpler:  
bp\_gc = ue.EditorAssetLibrary.load\_blueprint\_class(childBP.get\_path\_name())  
which skips needing the path vars all together

---

<div class="post-metadata">

**Author:** ![kprimo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kprimo](https://forums.unrealengine.com/u/kprimo)\
**Post date:** [July 18, 2023, 3:07pm UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129/3 "2023-07-18T15:07:29Z")

</div>

Hi, there. I found a way to get BP components with python api, try my functions:

```python
import unreal

def get_component_handles(blueprint_asset_path):
    subsystem = unreal.get_engine_subsystem(unreal.SubobjectDataSubsystem)

    blueprint_asset = unreal.load_asset(blueprint_asset_path)
    subobject_data_handles = subsystem.k2_gather_subobject_data_for_blueprint(blueprint_asset)
    return subobject_data_handles

def get_component_objects(blueprint_asset_path):
    objects = []
    handles = get_component_handles(blueprint_asset_path)
    for handle in handles:
        data = unreal.SubobjectDataBlueprintFunctionLibrary.get_data(handle)
        object = unreal.SubobjectDataBlueprintFunctionLibrary.get_object(data)
        objects.append(object)
    return objects

component_objects = get_component_objects('/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.BP_ThirdPersonCharacter')

```

if you print `component_objects`, will return:

```auto
LogPython: [<Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.Default__BP_ThirdPersonCharacter_C' (0x0000050161179800) Class 'BP_ThirdPersonCharacter_C'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.Default__BP_ThirdPersonCharacter_C:CollisionCylinder' (0x0000050167E84D00) Class 'CapsuleComponent'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.Default__BP_ThirdPersonCharacter_C:Arrow' (0x0000050167E84600) Class 'ArrowComponent'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.BP_ThirdPersonCharacter_C:CameraComponent_0__CCE3C0B4' (0
x0000050143A6CC00) Class 'CameraComponent'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.Default__BP_ThirdPersonCharacter_C:CharacterMesh0' (0x0000050161385000) Class 'SkeletalMeshComponent'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.BP_ThirdPersonCharacter_C:SpringArmComponent_0__A9892D03' (0x0000050147D1AC00) Class 'SpringArmComponent'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCharacter.BP_ThirdPersonCharacter_C:CameraComponent_0__CCE3C0B4' (0x0000050143A6CC00) Class 'CameraComponent'>, <Object '/Game/ThirdPerson/Blueprints/BP_ThirdPersonCha
racter.Default__BP_ThirdPersonCharacter_C:CharMoveComp' (0x000005013DECF000) Class 'CharacterMovementComponent'>]

```

---

<div class="post-metadata">

**Author:** ![chyren53](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@chyren53](https://forums.unrealengine.com/u/chyren53)\
**Post date:** [August 2, 2023, 9:00am UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129/4 "2023-08-02T09:00:07Z")

</div>

I did not post this question, but this work!  
Thank you so much. I am looking for this almost 1 year.

---

<div class="post-metadata">

**Author:** ![Sherry-Yuki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sherry-Yuki](https://forums.unrealengine.com/u/Sherry-Yuki)\
**Post date:** [November 3, 2023, 1:46pm UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129/5 "2023-11-03T13:46:01Z")

</div>

Than you so much, it works well in unreal 5.1 and 5.3, but it doesn’t work in Unreal 4.27, do you konw how to get components in 4.27?

---

<div class="post-metadata">

**Author:** ![Findodo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Findodo](https://forums.unrealengine.com/u/Findodo)\
**Post date:** [February 7, 2024, 11:45pm UTC](https://forums.unrealengine.com/t/python-get-component-from-ubgc-ublueprint/455129/6 "2024-02-07T23:45:38Z")

</div>

Really thank you for this , you set me on the right path !
