• 카테고리

    질문 & 답변
  • 세부 분야

    게임 프로그래밍

  • 해결 여부

    미해결

OnComponentBeginOverlap 바인드

24.03.30 12:01 작성 조회수 96

0

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "ABCharacterNPC.generated.h"

UCLASS()
class INFINITEABYSS_API AABCharacterNPC : public ACharacter
{
    GENERATED_BODY()

public:
    AABCharacterNPC();

protected:
    UPROPERTY(VisibleAnywhere, Category = NPC, Meta = (AllowPrivateAccess = "true"))
    TObjectPtr<class UStaticMeshComponent> NPC;

    UPROPERTY(VisibleAnywhere, Category = NPC, Meta = (AllowPrivateAccess = "true"))
    TObjectPtr<class UBoxComponent> NPCTrigger;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Collision")
    bool bIsOverlapping;

    UFUNCTION()
    void OnBoxTriggerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepHitResult);


};

헤더 파일에 이렇게 선언 한 다음

// Fill out your copyright notice in the Description page of Project Settings.


#include "NPC/ABCharacterNPC.h"
#include "Components/BoxComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/PrimitiveComponent.h"
#include "Physics/ABCollision.h"

// Sets default values
AABCharacterNPC::AABCharacterNPC()
{
    bUseControllerRotationPitch = false;
    bUseControllerRotationYaw = false;
    bUseControllerRotationRoll = false;

    GetCapsuleComponent()->InitCapsuleSize(42.0f, 96.0f);
    GetCapsuleComponent()->SetCollisionProfileName(TEXT("NPC"));

    GetMesh()->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, -95.0f), FRotator(0.0f, 0.0f, 0.0f));
    GetMesh()->SetAnimationMode(EAnimationMode::AnimationBlueprint);
    GetMesh()->SetCollisionProfileName(TEXT("NPCMesh"));

    static ConstructorHelpers::FObjectFinder<USkeletalMesh> NPCMeshRef(TEXT("/Script/Engine.SkeletalMesh'/Game/ExternAssets/MedievalGirl/Mesh/SK_MedievalGirl.SK_MedievalGirl'"));
    if (NPCMeshRef.Object)
    {
        GetMesh()->SetSkeletalMesh(NPCMeshRef.Object);
    }

    static ConstructorHelpers::FClassFinder<UAnimInstance> AnimInstanceClassRef(TEXT("Game/ExternAssets/MedievalGirl/Demo/Animations/ThirdPerson_AnimBP.ThirdPerson_AnimBP_C"));
    if (AnimInstanceClassRef.Class)
    {
        GetMesh()->SetAnimInstanceClass(AnimInstanceClassRef.Class);
    }

    NPCTrigger = CreateDefaultSubobject<UBoxComponent>(TEXT("NPCTrigger"));
    NPCTrigger->SetBoxExtent(FVector(100.0f, 100.0f, 100.0f));
    NPCTrigger->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
    NPCTrigger->SetupAttachment(GetMesh());
    NPCTrigger->SetCollisionProfileName(CPROFILE_ABTRIGGER);
    NPCTrigger->OnComponentBeginOverlap.AddDynamic(this, &AABCharacterNPC::OnBoxTriggerBeginOverlap);

    UE_LOG(LogTemp, Log, TEXT("NPC Trigger event binding: %s"), NPCTrigger->OnComponentBeginOverlap.IsBound() ? TEXT("Success") : TEXT("Failed"));

    bIsOverlapping = false;

}

void AABCharacterNPC::OnBoxTriggerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
    UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepHitResult)
{
    UE_LOG(LogTemp, Log, TEXT("%s"), *OtherActor->GetName());
    
    bIsOverlapping = true;
}

Cpp 파일에 OnBoxTriggerBeginOverlap를 바인드 해서 사용할려는데 로그로 바인드는 되었다고 뜨는데 함수안에 있는 로그는 왜 안찍히는 건가요?

답변 2

·

답변을 작성해보세요.

0

아 코드로는 문제 없어보였는데 해결되었다니 다행이네요

0

신동주님의 프로필

신동주

질문자

2024.03.30

문제 해결 했습니다...
오브젝트 삭제하고 다시 설치 하니까 체크가 되었습니다.
언리얼 Generate 까지 했는데 안되어서 코드 문제 인줄 알았는데...