Download

Inherited SpringArm doesnt rotate with it's parent component which is a raw inherited SCeneComponent

First off, sorry if this is posted under the wrong topic, but I’m unsure of where to post this, since I’m sure the code I’ve written works 100%, and I can prove it. However, I haven’t done anything of this project in BP visual scripting either.

I’ve got a problem rotating my spring arm since it doesn’t rotate with its parent which I use for the horizontal rotation. Some background, I’ve created a ACharacter in C++, and I’m trying to rotate the camera horizontally and vertically. Input is received through a C++ APlayerController. I also have a Blueprint of this class which is being used, so I can tweak the values, and yes, I have disabled the following on the SpringArm: bInheritPitch, bInheritYaw, bPitchInheritRoll, and UsePawnControlRotation.

It works perfectly to directly rotate the spring arm vertically! Also, I’ve even tried manually rotating the SceneComponent (HorizontalGimbal) in the BP’s viewport, and the SpringArm doesn’t even respond to the rotations when they’re made in the viewport. To test that the code works, I even added a static mesh component which I childed to the SceneComponent (HorizontalGimbal) just to see if it’s being rotated with its parent during runtime, and it is being rotated with the parent during runtime.

A few images before the code to illustrate the issue:

Here’s the ACharacter’s constructor:

AThirdPersonPlayer::AThirdPersonPlayer()
{
PrimaryActorTick.bCanEverTick = true;
InputMoveDirection = FVector::ZeroVector;
GamepadInputRotateZ = 0.0f;
GamepadInputRotateY = 0.0f;
MouseInputRotateZ = 0.0f;
MouseInputRotateY = 0.0f;
HorizontalGimbal = CreateDefaultSubobject<USceneComponent>(TEXT(“HorizontalGimbal”));
HorizontalGimbal->SetupAttachment(RootComponent);
SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT(“SpringArm”));
SpringArmComponent->SetupAttachment(HorizontalGimbal);
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT(“Camera”));
CameraComponent->SetupAttachment(SpringArmComponent);
}

and here’s the ACharacter’s HandleCameraRotation method which is called in the tick method:

void AThirdPersonPlayer::HandleCameraRotation(float DeltaTime)
{
if (HorizontalGimbal && GamepadInputRotateZ + MouseInputRotateZ != 0.0f)
{
const float RotationDelta = 1.0f * (GamepadInputRotateZ + MouseInputRotateZ) * DeltaTime * CameraRotationSpeed;
const FRotator NewRotation(0.0f, RotationDelta, 0.0f);
HorizontalGimbal->AddLocalRotation(NewRotation, true, nullptr, ETeleportType::None);
}

if (SpringArmComponent && GamepadInputRotateY + MouseInputRotateY != 0.0f)
{
const float CurrentRotationY = SpringArmComponent->GetRelativeTransform().GetRotation().Euler().Y;
const float RotationDelta = 1.0f * (GamepadInputRotateY + MouseInputRotateY) * DeltaTime * CameraRotationSpeed;

if (RotationDelta > 0.0f && CurrentRotationY + RotationDelta > CameraRotationCapUpwards ||
RotationDelta < 0.0f && CurrentRotationY - RotationDelta < CameraRotationCapDownwards)
{
return;
}

const FRotator NewRotation(RotationDelta, 0.0f, 0.0f);
SpringArmComponent->AddLocalRotation(NewRotation, true, nullptr, ETeleportType::None);
}
}

Once again, sorry if this is in the wrong topic! I appreciate any help I can get, thanks in advance!

Ehm, trying to figure out how to properly format blocks of code, this obviously was meant for inline code. Bare with me …