2강 캐릭터와 입력시스템: compile error로 인해 코드를 적용할 수 없습니다.
10000자 제한으로 인해서 답글로 코드를 올립니다.아래가 제가 작성한 ABCharacter.cpp 파일입니다.// Fill out your copyright notice in the Description page of Project Settings. #include "Character/ABCharacterPlayer.h" #include "Camera/CameraComponent.h" #include "GameFramework/SpringArmComponent.h" #include "InputMappingContext.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" AABCharacterPlayer::AABCharacterPlayer() { // Camera CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 400.0f; CameraBoom->bUsePawnControlRotation = true; FollowCamera = CreateDefaultSubobject(TEXT("FollowCamera")); FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // springArm에 자동으로 달라붙는다. FollowCamera->bUsePawnControlRotation = false; // Input static ConstructorHelpers::FObjectFinder InputMappingContextRef(TEXT("/Script/EnhancedInput.InputMappingContext'/Game/ArenaBattle/Input/IMC_Default.IMC_Default'")); if (InputMappingContextRef.Object != nullptr) { DefaultMappingContext = InputMappingContextRef.Object; } static ConstructorHelpers::FObjectFinder InputActionMoveRef(TEXT("/Script/EnhancedInput.InputAction'/Game/ArenaBattle/Input/Actions/IA_Move.IA_Move'")); if (InputActionMoveRef.Object != nullptr) { MoveAction = InputActionMoveRef.Object; } static ConstructorHelpers::FObjectFinder InputActionJumpRef(TEXT("/Script/EnhancedInput.InputAction'/Game/ArenaBattle/Input/Actions/IA_Jump.IA_Jump'")); if (InputActionJumpRef.Object != nullptr) { JumpAction = InputActionJumpRef.Object; } static ConstructorHelpers::FObjectFinder InputActionLookRef(TEXT("/Script/EnhancedInput.InputAction'/Game/ArenaBattle/Input/Actions/IA_Look.IA_Look'")); if (InputActionLookRef.Object != nullptr) { LookAction = InputActionLookRef.Object; } } void AABCharacterPlayer::BeginPlay() { Super::BeginPlay(); APlayerController* PlayerController = CastChecked(GetController()); if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController)) { // mapping context 추가 Subsystem->AddMappingContext(DefaultMappingContext, 0); // 우선순위를 지정해서 다양한 input이 서로 겹칠 때 우선순위가 높은 입력을 먼저 처리 // 런타임에서 해당 함수를 이용해서 뺄 수 있다. // Subsystem->RemoveMappingContext(DefaultMappingContext); } } void AABCharacterPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); // 반드시 Enhance Input System을 쓰도록 세팅 // CastChecked를 통해 해당 input system을 쓰지 않으면 에러를 발생시킨다. UEnhancedInputComponent* EnhancedInputComponent = CastChecked(PlayerInputComponent); // 생성자에서 만든 Action을 함수와 binding 한다. // Jump와 StopJumping는 Character가 제공하는 함수 API이다. EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump); EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::StopJumping); EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AABCharacterPlayer::Move); EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AABCharacterPlayer::Look); } void AABCharacterPlayer::Move(const FInputActionValue& Value) // Value에 xy 값을 가져온다. { FVector2D MovementVector = Value.Get(); const FRotater Rotation = Controller->GetControlRotation(); const FRotater YawRotation(0, Rotation.Yaw, 0); const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); // Value에서 가져온 x, y 값을 Movement Component와 연결한다. AddMovementInput(ForwardDirection, MovementVector.X); AddMovementInput(RightDirection, MovementVector.Y); } void AABCharacterPlayer::Look(const FInputActionValue& Value) { FVector2D LookAxisVector = Value.Get(); // controller의 회전 설정으로 카메라의 springArm이 해당 component를 바라보도록 설정 AddControllerYawInput(LookAxisVector.X); AddControllerYawInput(LookAxisVector.Y); }