Download

Overlap event on BoxCollision not work

// Sets default values
AMyCharacter1::AMyCharacter1()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(GetRootComponent());
CameraBoom->TargetArmLength = 200.f;
CameraBoom->bUsePawnControlRotation = true;

//GetCapsuleComponent()->SetCapsuleSize(48.f, 105.f);

FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = false;

BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
BoxCollision->AttachToComponent(GetMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("hand_r"));

}

// Called when the game starts or when spawned
void AMyCharacter1::BeginPlay()
{
Super::BeginPlay();

BoxCollision->OnComponentBeginOverlap.AddDynamic(this, &AMyCharacter1::OnOverlapBegin);

}

// Called every frame
void AMyCharacter1::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

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

check(PlayerInputComponent);

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

PlayerInputComponent->BindAxis("LookUp", this, &AMyCharacter1::AddControllerPitchInput);
PlayerInputComponent->BindAxis("Turn", this, &AMyCharacter1::AddControllerYawInput);

PlayerInputComponent->BindAction("Crounch", IE_Pressed, this, &AMyCharacter1::BeginCrounch);
PlayerInputComponent->BindAction("Crounch", IE_Released, this, &AMyCharacter1::EndCrounch);

PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AMyCharacter1::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AMyCharacter1::StopJumping);

PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &AMyCharacter1::OnFight);

}

void AMyCharacter1::MoveForward(float Value)
{
AddMovementInput(GetActorForwardVector() * Value);
}

void AMyCharacter1::MoveRight(float Value)
{
AddMovementInput(GetActorRightVector() * Value);
}

void AMyCharacter1::BeginCrounch()
{
Crouch();
}

void AMyCharacter1::EndCrounch()
{
UnCrouch();
}

FVector AMyCharacter1::GetPawnViewLocation() const
{
if (CameraBoom)
{
return CameraBoom->GetComponentLocation();
}

return Super::GetPawnViewLocation();

}

void AMyCharacter1::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor)
{
EPhysicalSurface SurfaceType = UPhysicalMaterial::DetermineSurfaceType(SweepResult.PhysMaterial.Get());

    if (SurfaceType == Body)
    {
    //    UE_LOG(LogTemp, Warning, TEXT("TEST1"));
    }
}

}

void AMyCharacter1::OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{

}

void AMyCharacter1::OnFight()
{
//UE_LOG(LogTemp, Warning, TEXT(“TEST15”));
if (AnimMontage != NULL)
{
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance != NULL)
{
AnimInstance->Montage_Play(AnimMontage, 1.f);
AnimInstance->Montage_JumpToSection(FName(“Default”), AnimMontage);
}
}
}