Unreal

[Unreal5] 입력 설정 함수

usingsystem 2024. 6. 5. 09:35
728x90

SetupInputComponent

APawn 클래스와 그 하위 클래스에서 사용되는 함수입니다. 이 함수는 Pawn에 대한 입력 설정을 처리합니다. AActor 클래스에서도 사용될 수 있습니다.

.h

protected:
    // Called to bind functionality to input
    virtual void SetupInputComponent() override;
    
    // Movement functions
    void MoveForward(float Value);
    void MoveRight(float Value);

.cpp

void AMyPawn::SetupInputComponent()
{
    Super::SetupInputComponent();

    InputComponent->BindAxis("MoveForward", this, &AMyPawn::MoveForward);
    InputComponent->BindAxis("MoveRight", this, &AMyPawn::MoveRight);
}

SetupPlayerInputComponent

ACharacter 클래스와 그 하위 클래스에서 사용되는 함수입니다. 이 함수는 주로 캐릭터의 입력 설정을 처리합니다.

.h

protected:
    // Called to bind functionality to input
    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
    
    // Movement functions
    void MoveForward(float Value);
    void MoveRight(float Value);

.cpp

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

    PlayerInputComponent->BindAxis("MoveForward", this, &AMyCharacter::MoveForward);
    PlayerInputComponent->BindAxis("MoveRight", this, &AMyCharacter::MoveRight);
}

 

728x90