강의

멘토링

로드맵

Inflearn brand logo image

인프런 커뮤니티 질문&답변

ajkdfj님의 프로필 이미지
ajkdfj

작성한 질문수

이득우의 언리얼 프로그래밍 Part2 - 언리얼 게임 프레임웍의 이해

캐릭터가 갑자기 안 움직입니다ㅜ

작성

·

126

0

#include "InputMappingContext.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"

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

	APlayerController* PlayerController = CastChecked<APlayerController>(GetController());
	if (PlayerController)
	{
		if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
		{
			Subsystem->AddMappingContext(DefaultMappingContext, 0);
		}
	}

}

// Called to bind functionality to input
void ACharacterPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent);

	EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
	EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
	EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ALCharacterPlayer::Move);
	EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACharacterPlayer::Look);
	EnhancedInputComponent->BindAction(AttackAction, ETriggerEvent::Triggered, this, &ACharacterPlayer::Attack);

}

void ACharacterPlayer::Move(const FInputActionValue& Value)
{
	FVector2D MovementVector = Value.Get<FVector2D>();	

	const FRotator Rotation = Controller->GetControlRotation();	
	const FRotator YawRotation(0, Rotation.Yaw, 0);


	const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

	AddMovementInput(ForwardDirection, MovementVector.X);
	AddMovementInput(RightDirection, MovementVector.Y);
}

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

	AddControllerYawInput(LookVector.X);
	AddControllerPitchInput(LookVector.Y);

}

코드는 위와 같이 작성을 했습니다. 화요일까지 움직였는데 갑자기 안 움직입니다. 플러그인도 있고, IMC에도 다 설정을 했는데 갑자기 안 움직입니다... 구글에서 찾아봐도 해결이 안됩니다ㅜㅜ...

ThirdPersonCharacter 를 추가해서 이 캐릭터를 사용하니 움직입니다. 그래서 ThirdPersonCharacter 의 부모 클래스를 제가 만든 클래스로 설정을 하니 다시 안 움직입니다. 코드 문제인 거 같은데 뭐가 문제인걸까요..

답변 2

0

이득우님의 프로필 이미지
이득우
지식공유자

AddMovementInput이 실제로 호출되는지 디버깅으로 확인해보시고, 컨트롤러가 점유한 플레이어 폰에 MovementComponent가 배치되었는지 보면 될 것 같습니다.

ajkdfj님의 프로필 이미지
ajkdfj
질문자

플레이어 폰에는 아래 사진과 같이 캐릭터 무브먼트 컴포넌트가 배치가 되어있습니다.

스크린샷 2025-02-17 103424.png

다른 곳에서는 AddMappingContext를 컨트롤러에 하면 되는 경우도 있다고 하여 아래 사진과 같이 컨트롤러 블루프린트에서 AddMappingContext를 해주었습니다. 캐릭터 코드에서는 주석을 하였습니다.

image.png
 void ALuckyCharacterPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	UE_LOG(LogTemp, Error, TEXT("SetupPlayerInputComponent"));
	// EnhancedInputComponent를 사용하지 않는다면 에러가 나도록 체크
	UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent);
	if (EnhancedInputComponent)
	{
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ALuckyCharacterPlayer::Move);
		EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALuckyCharacterPlayer::Look);
		EnhancedInputComponent->BindAction(AttackAction, ETriggerEvent::Triggered, this, &ALuckyCharacterPlayer::Attack);
		UE_LOG(LogTemp, Display, TEXT("Use EnhancedInputComponent"));
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("Not EnhancedInputComponent"));
	}
}

void ALuckyCharacterPlayer::Move(const FInputActionValue& Value)
{
	FVector2D MovementVector = Value.Get<FVector2D>();	// x, y 입력 값으로 받아오기

	const FRotator Rotation = Controller->GetControlRotation();	// 현재 카메라 회전 가져오기
	const FRotator YawRotation(0, Rotation.Yaw, 0);

	// 전방 및 측면 방향 계산
	const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

	AddMovementInput(ForwardDirection, MovementVector.X);
	UE_LOG(LogTemp, Display, TEXT("AddMovementInput Forward: %f"), MovementVector.X);
	AddMovementInput(RightDirection, MovementVector.Y);
	UE_LOG(LogTemp, Display, TEXT("AddMovementInput Right: %f"), MovementVector.Y);
	UE_LOG(LogTemp, Display, TEXT("Move"));
}

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

	AddControllerYawInput(LookVector.X);
	AddControllerPitchInput(LookVector.Y);
	UE_LOG(LogTemp, Display, TEXT("Rotation"));
}

void ALuckyCharacterPlayer::Attack()
{
	UE_LOG(LogTemp, Display, TEXT("Attack"));
	AttackPress();
}

위 코드와 같이 로그를 추가하였는데, 로그는 절대 나타나지 않습니다. SetupPlayerInputComponent 이 로그만 나타납니다.

다른 곳에서 물었을 때에는 바인딩을 플레이어 폰의 블루프린트에서 해라고 하였습니다. 그래서 해보았더니 뷰포트에 로그들은 뜨는데 절대 움직이지 않습니다..

image.png

 

 

그리고 방금 다시 실행을 해보니 크래쉬가 발생을 했습니다.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000030

UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Lucky!ALuckyCharacterBase::ComboAttackStart() [D:\Project\Lucky\Source\Lucky\Character\LuckyCharacterBase.cpp:82]
UnrealEditor_Lucky!TBaseUObjectMethodDelegateInstance<0,ALuckyCharacterPlayer,void __cdecl(void),FDefaultDelegateUserPolicy>::Execute() [D:\UE_5.3\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:650]
UnrealEditor_Lucky!TEnhancedInputUnifiedDelegate<TDelegate<void __cdecl(void),FDefaultDelegateUserPolicy> >::Execute<>() [D:\UE_5.3\Engine\Plugins\EnhancedInput\Source\EnhancedInput\Public\EnhancedInputComponent.h:110]
UnrealEditor_EnhancedInput
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

ComboAttackStart의 함수 82번째 줄에는 FOnMontageEnded ComboEndDelegate; 이 코드인데 뭐가 문제인건지 모르겠습니다..

이득우님의 프로필 이미지
이득우
지식공유자

입력 시스템이 전혀 동작하지 않는다면 프로젝트 설정을 한 번 점검해보면 좋겠습니다.
일단 이렇게 단편적인 코드만 봐서는 문제 상황을 점검하기 어렵고 결국 디버깅을 잘 해야 합니다.
크래시가 나는 문제에 대해서는 강의에서 설명한대로 엔진에 디버깅 심볼을 설치해 원인을 파악해야 할 것 같아요.

0

안녕하세요, 인프런 AI 인턴입니다.

ajkdfj님께서 언리얼 엔진에서 캐릭터가 갑자기 움직이지 않는 문제로 고민 중이시군요. 일반적으로 이런 문제가 발생할 때는 코드의 설정, 입력 매핑, 혹은 부모 클래스 설정에서 문제가 있을 수 있습니다.

  1. 입력 매핑 설정 확인: 우선, 입력 매핑이 올바르게 설정되어 있는지 다시 한번 확인해 보세요. DefaultMappingContext가 제대로 설정되어 있는지, 그리고 MoveAction, JumpAction, LookAction, AttackAction 등이 정상적으로 매핑되어 있는지를 체크하세요. InputMappingContextInputAction 경로가 변경된 경우, 올바른 경로를 지정해야 합니다.

  2. 컨트롤러 설정 확인: APlayerController* PlayerController = CastChecked<APlayerController>(GetController()); 부분에서 PlayerController가 null이 아닌지, 그리고 올바르게 캐스팅되고 있는지를 확인해 보세요. 캐스팅에 문제가 있다면, 입력이 정상적으로 전달되지 않을 수 있습니다.

  3. 코드 비교: 또 다른 캐릭터가 정상적으로 움직인다 하셨으니, 해당 캐릭터의 설정과 지금 작성하신 ACharacterPlayer 클래스의 설정을 비교해 보시는 것도 좋은 방법입니다. 실행 시 비슷한 구문이 실행되고 있는지 확인합니다.

아래 링크는 유사한 문제를 겪으신 다른 수강생의 질문과 답변입니다. 제공된 해결 방법을 참고하면 도움이 될 수 있습니다:

해당 링크들은 다른 수강생님들도 겪었던 문제점들과 그 해결 방법들이 논의되어 있어서 도움이 되실 것 같습니다. 특히 입력 매핑 및 컨트롤러 설정과 관련된 문제들은 주의를 요합니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

ajkdfj님의 프로필 이미지
ajkdfj

작성한 질문수

질문하기