class UWidgetComponent;
public:
virtual void LeftClickInteract(AActor* Interactor) override;
virtual EInteractionType GetInteractionType_Implementation() const override;
virtual void BeginHighlight() override;
virtual void EndHighlight() override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
TObjectPtr<UWidgetComponent> InteractionWidget;
#include "Components/WidgetComponent.h"
ALNHarmonyPlayActor::ALNHarmonyPlayActor()
{
// Root Component
GemMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("GemMesh"));
RootComponent = GemMesh;
GemMesh->SetCustomDepthStencilValue(255);
GemMesh->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
GemMesh->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
InteractionWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("InteractionWidget"));
InteractionWidget->SetupAttachment(GemMesh);
InteractionWidget->SetWidgetSpace(EWidgetSpace::Screen);
InteractionWidget->SetVisibility(false);
InteractionWidget->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
void ALNHarmonyPlayActor::BeginPlay()
{
Super::BeginPlay();
if (GemMesh)
{
GemMesh->SetRenderCustomDepth(false);
}
}
void ALNHarmonyPlayActor::LeftClickInteract(AActor* Interactor)
{
// 좌클릭 시 일어날 상호작용
Interact();
}
EInteractionType ALNHarmonyPlayActor::GetInteractionType_Implementation() const
{
return EInteractionType::LeftClick;
}
void ALNHarmonyPlayActor::BeginHighlight()
{
if (GemMesh)
{
GemMesh->SetRenderCustomDepth(true);
}
if (InteractionWidget)
{
InteractionWidget->SetVisibility(true);
}
}
void ALNHarmonyPlayActor::EndHighlight()
{
if (GemMesh)
{
GemMesh->SetRenderCustomDepth(false);
}
if (InteractionWidget)
{
InteractionWidget->SetVisibility(false);
}
}
이렇게 하니까 하이라이트 + 상호작용 UI 표시가 나오지 않았다.
메시 컴포넌트에 충돌 설정이 명시적으로 없어서 코드 추가하기
생성자에서 메시 컴포넌트에 충돌 설정 코드 넣기
GemMesh->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
GemMesh->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
상호작용 UI는 나왔는데 하이라이트 표시가 안 나왔다.
레벨에 Post Process Volume 배치를 하고 하이라이트 머티리얼을 설정해줘야 한다.

