USpringArmComponent doesn't move when bUsePawnControlRotation set to true

Hi!

I’m using this in my character class:


ASCharacter::ASCharacter()
{
	PrimaryActorTick.bCanEverTick = true;

	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComp"));
	SpringArmComp->SetupAttachment(RootComponent);
	SpringArmComp->TargetArmLength = 400.0f;
	SpringArmComp->bUsePawnControlRotation = true;
	
	CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComp"));
	CameraComp->SetupAttachment(SpringArmComp, USpringArmComponent::SocketName);
	CameraComp->bUsePawnControlRotation = false;

}

void ASCharacter::BeginPlay()
{
	Super::BeginPlay();

	//Add Input Mapping Context
	if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
	{
		if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
		{
			Subsystem->AddMappingContext(DefaultMappingContext, 0);
		}
	}
	
}

void ASCharacter::Look(const FInputActionValue& Value)
{
	FVector2D LookAxisVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// add yaw and pitch input to controller
		AddControllerYawInput(LookAxisVector.X);
		AddControllerPitchInput(LookAxisVector.Y);
	}
}

void ASCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
	{
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ASCharacter::Move);
		
		EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ASCharacter::Look);
	}

}

But it doesn’t turn or look up, but it moves.

Have I forgotten anything?

I have no idea about enhanced input, so I have copied the code from the Third Person Template.

Thanks!

are you using Mouse, gamepad, or keyboard buttons for look? Same question for the Move?

make sure you have an InputAction for your Look and make sure that the settings for the axis are “as expected”

  • Y positive is a “Swizzle”
  • Y negative is a “Swizzle” and “Negate”
  • X negative is a “Negate”

did you remember to assign the InputActions in the Blueprint for the Character (I hope you are not using hard, runtime resolved references)

I am unsure you mean by “doesn’t turn” do you mean that the character model doesn’t rotate? that the camera doesn’t orbit the character?

Thanks for your answer.

I use the mouse in both projects, mine and the third person project.

I have double checked what I did with the third person project, and everything is the same. But, probably, I’ve missed something.

About the input actions:

This is my Input Action to Look:

And my IMC_Default:

The blueprint class, that inherits from the C++ class, has everything set for the inputs:

The input actions in the C++ of the Character class:


UCLASS()
class ACTIONROUGELIKE_API ASCharacter : public ACharacter
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess="true"))
	class UInputMappingContext* DefaultMappingContext;

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* MoveAction;

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* LookAction;

The camera doesn’t orbit around the character and the character doesn’t rotate.

Thanks.

If I set this to the camera in the character’s blueprint class:

The camera rotates up and down, and left to right. And also, the character moves its head (I’m using Gideon’s mesh and its animation).

So, I think, the problem is with the USpringArmComponent.

The solution for this problem is:

  • Create a new Blueprint class that inherits from the C++ Character class.

  • Set the Input mapping context and input mapping actions.

  • Set the mesh and animation.

  • Used it into the level.

And now it works!

I would like to know why it doesn’t work with the first blueprint class. Is there a way to compare two blueprint classes to see what the differences are?

Thanks.

there is a built in tool for blueprints

the functionality of the tool is Engine version dependent, and might not be great when looking at similar but different things.

for the C++ those are just text files, so anything like WinMerge can diff those.

1 Like

I have used the diff tool to know the differences between both, and there is only one:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.