# Move a UChildActorComponent's subcomponent, snap parent actor RootComponent

**URL:** <https://forums.unrealengine.com/t/move-a-uchildactorcomponents-subcomponent-snap-parent-actor-rootcomponent/403915>\
**Category:** World Creation\
**Tags:** Procedural-Generation, child-actors, unreal-engine, transform, world-position, CPP, question\
**Created:** [September 6, 2017, 6:15pm UTC](https://forums.unrealengine.com/t/move-a-uchildactorcomponents-subcomponent-snap-parent-actor-rootcomponent/403915 "2017-09-06T18:15:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_73746a831](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_73746a831](https://forums.unrealengine.com/u/anonymous_user_73746a831)\
**Post date:** [September 6, 2017, 6:15pm UTC](https://forums.unrealengine.com/t/move-a-uchildactorcomponents-subcomponent-snap-parent-actor-rootcomponent/403915/1 "2017-09-06T18:15:38Z")

</div>

I have a procedurally generated map where I know where I want to place things and am using Arrow Component to lego piece blocks together.

Here is my Actor (nodes) and Child Actor (node edges) component setup

```
USceneComponent = Root (ANode)
    UMeshComponent
    UChildActorComponent
           USceneComponent = Root (ANodeEdge)
                 UArrowComponent
                 UBoxComponent
    UChildActorComponent
            ...

```

Now, I SetWorldTransform() for one arrow component to where I want it to be, but it moves relative of everything else. I am guessing I need to calculate an offset and move the Node root component instead. I have been experimenting but can’t get it to snap correctly.

What offset do I need to calculate for “Node” USceneComponent when I know exactly what world transform I want for the child “NodeEdge” UArrowComponent? Or maybe there is a way to lock the transforms together?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_73746a831](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_73746a831](https://forums.unrealengine.com/u/anonymous_user_73746a831)\
**Post date:** [September 7, 2017, 7:20am UTC](https://forums.unrealengine.com/t/move-a-uchildactorcomponents-subcomponent-snap-parent-actor-rootcomponent/403915/2 "2017-09-07T07:20:59Z")

</div>

Well, I realized I had to apply the rotations before the translations in order to get proper offsets.

I’ll just leave this here…

```
void SnapParentToChildSubComponent(AActor* const Parent, 
                                   const USceneComponent* const Offset, 
                                   const FTransform& TowardTransform)
{
	// Step 0. Calculate and apply mirror rotation to update world space
	FRotator SnapRotator = TowardTransform.Rotator();
	const float ParentYaw = Parent->GetTransform().Rotator().Yaw;
	const float OffsetYaw = Offset->GetComponentTransform().Rotator().Yaw;
	const float TowardYaw = SnapRotator.Yaw;

	SnapRotator.Yaw -= 180.f;
	SnapRotator.Yaw += (ParentYaw - OffsetYaw);

	Parent->SetActorRotation(SnapRotator.Quaternion());
	
	// Step 1. Calculate and apply distance offsets
	const FVector ParentTranslation = Parent->GetTransform().GetLocation();
	const FVector OffsetTranslation = Offset->GetComponentTransform().GetLocation();
	const FVector TowardTranslation = TowardTransform.GetLocation();

	const FVector SnapTranslation = TowardTranslation + 
                                    (ParentTranslation - OffsetTranslation);

	Parent->SetActorLocation(SnapTranslation);
}

```
