Rotation Problem

Hey there,
I’m working on this room connection class method (part of a larger map generation system) which rotates the top level actor then moves it so the two connection components are facing each other and exist at the same coordinates in world space.
It’s at least partly working, the function works flawlessly no matter what component I pick on the target room, but if I choose anything other than the first connection point (element 0) from GetConnectionPoints on the room I’m moving, the rotation is off by the relative yaw value of the connection point.

I’ve been trying to debug this for a week and I’m sure there’s something obvious in here that I’m missing.

void URoomConnectionComponent::ConnectTo(URoomConnectionComponent* target, bool typeOverride)
	if (connectionType == target->GetConnectionType() || typeOverride == true)
		AActor* rootActor = GetAttachmentRootActor();
		FRotator targetRotation = target->GetComponentRotation();
		targetRotation.Add(0.0f, 180.0f, 0.0f);
		targetRotation = targetRotation.Clamp();
		FVector distanceToTarget = target->GetComponentLocation() - GetComponentLocation();
		UE_LOG(LogTemp, Error, TEXT("Tried to connect non-matching rooms without an override"));

Here’s the result using the connection point with 90deg yaw on room1 and the component with 0deg yaw on room2. The little cube indicates the positive X value for sense of direction.
The connection points which are connected are in front of the little cube there.

Ok, I managed to figure this out over lunch.
My problem was that I didn’t take into account the relative yaw of the component. Since I am rotating the actor and not the component itself, the yaw value has to be added to the target rotation.
I’m guessing it’ll look something like this:


This ended up being the solution:
targetRotation -= GetRelativeTransform().Rotator();