작성
·
220
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를 바인드 해서 사용할려는데 로그로 바인드는 되었다고 뜨는데 함수안에 있는 로그는 왜 안찍히는 건가요?
저도 이 문제였네요; 변수 지웠다가 다시 생성하니까 바인딩된 함수 호출 되네요;;
아무래도 헤더 소스코드 파싱에서 문제가 있었던게 아닐까... 생각되네요.
해결법 공유 감사합니다.