# Attaching USceneComponent to another Component

**URL:** <https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493>\
**Category:** Platform & Builds\
**Tags:** attach, add-component, attach-to-component, unreal-engine, question\
**Created:** [August 29, 2020, 7:23am UTC](https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493 "2020-08-29T07:23:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nterheoid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nterheoid](https://forums.unrealengine.com/u/nterheoid)\
**Post date:** [August 29, 2020, 7:23am UTC](https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493/1 "2020-08-29T07:23:47Z")

</div>

trying attach a USceneComponent to my UCameraComponent by codes below:

```
    //create components
    Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    SceneComp = CreateDefaultSubobject<UGrabber>(TEXT("SceneComp"));
    
    //attach Camera to current root
    Camera->SetupAttachment(GetRootComponent());
    
    //attah my SceneComp to Camera making it a hierarchy.
    SceneComp->AttachToComponent(Camera,FAttachmentTransformRules::SnapToTargetIncludingScale);

```

the result visually looks great in editor:

Root

----Camera

--------SceneComp

but when i try for getting world location of my SceneComp using GetComponentLocation(),

whole editor was crashed:

```
void AFirstPersonCharacter::BeginPlay()
{
    Super::BeginPlay();
    FString start = Grabber->GetComponentLocation().ToString(); <---crashed on this line.
    UE_LOG(LogTemp,Warning,TEXT("SceneComp is at: %s"),*start);
}

```

it seems like the way of attaching USceneComponent to another component was mistaken.  
anyone could help?

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [August 29, 2020, 7:55am UTC](https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493/2 "2020-08-29T07:55:35Z")

</div>

FString start = SceneComp-\>GetComponentLocation().ToString();

---

<div class="post-metadata">

**Author:** ![nterheoid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nterheoid](https://forums.unrealengine.com/u/nterheoid)\
**Post date:** [August 31, 2020, 6:44am UTC](https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493/3 "2020-08-31T06:44:07Z")

</div>

sorry for line 4 on 2nd code block:

```
FString start = Grabber->GetComponentLocation().ToString(); <---crashed on this line.

```

**"Grabber" is just a TYPO on the post, doesn’t matter to the topic.**

should be SceneComp → GetComponentLocation() though.

---

<div class="post-metadata">

**Author:** ![nterheoid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nterheoid](https://forums.unrealengine.com/u/nterheoid)\
**Post date:** [August 31, 2020, 6:44am UTC](https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493/4 "2020-08-31T06:44:40Z")

</div>

Hey EvilCleric! you saved my life numberless times!  
but my post here is sorta a mess.  
i updated it with more coverd details on reddit,  
[attach a component which inherited from USceneComponent to another Component](https://www.reddit.com/r/unrealengine/comments/iip0h2/attach_a_component_which_inherited_from/)

> **[r/unrealengine - attach a component which inherited from USceneComponent to...](https://www.reddit.com/r/unrealengine/comments/iip0h2/attach_a_component_which_inherited_from/)**
>
> 1 vote and 0 comments so far on Reddit

could you have a look when you at convenience?  
thank you!

btw, do you know is it possible to edit/delete posted post in UE4 answerhub?

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [August 31, 2020, 7:47am UTC](https://forums.unrealengine.com/t/attaching-uscenecomponent-to-another-component/470493/5 "2020-08-31T07:47:04Z")

</div>

Try protecting your pointer:

```
if (Grabber)
{
    FString start = Grabber->GetComponentLocation().ToString(); 
    UE_LOG(LogTemp,Warning,TEXT("SceneComp is at: %s"),*start);
}
else
{
 UE_LOG(LogTemp,Error,TEXT("GRABBER COMP INVALID"));
}

```

Also, what is the UGrabber component?

Also, the crash log would really help.
