12일
hitResult의 위치를 가져와서
거기에 띄우면 될듯!!! 진짜임
13일
hitResult가 부딪힌 액터의 위치를 가져와서
ProjectWorldLocationToScreen을 사용해서 FVector를 FVector2D로 바꿔줌
SetPositionInViewport로 위젯을 2D벡터 자리에 띄워줌
void AHamsterDemoCharacter::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
FHitResult hitResult;
if (TraceOn(hitResult))
{
auto interactableObj = TraceInteractableObject(hitResult); // 감지한 물체가 상호 작용 가능한 물체인 지 체크
if (interactableObj != nullptr)
{
bool isSuccessInteract = interactableObj->Interact(); // 물체에게 상호 작용 시도
if (isSuccessInteract)
{
Widget->SetPositionInViewport(textLocation);
Widget->AddToViewport(); //위젯 띄우기
}
// 상호 작용 성공 시 캐릭터가 할 행동
}
}
}
}
AInteractableObject* AHamsterDemoCharacter::TraceInteractableObject(struct FHitResult& inHit)
{
auto actor = inHit.GetActor();
if (actor == nullptr)
return nullptr;
const APlayerController* const PlayerController = Cast<const APlayerController>(GetController());
FVector WorldLocation= actor->GetActorLocation();
PlayerController->ProjectWorldLocationToScreen(WorldLocation, textLocation);
return Cast<AInteractableObject>(actor);
}
이제 상호 작용 가능한 액터 자리에 텍스트가 뜬다.
위젯(텍스트)이 이미 띄워져 있으면 띄우지 않는 기능, 위젯이 3초 후 사라지는 기능도 넣어야 함
<위젯이 이미 있으면 띄우지 않는 기능>
IsInViewport (블루프린트에는 있는데 코드로는 어떻게 하는지 모르겠음)?
IsVisible?
<위젯 n초 후 사라지기>
Delay 후 RemoveFromParents
FTimerHandle WaitHandle;
float WaitTime = 1.0;
GetWorld()->GetTimerManager().SetTimer(WaitHandle, FTimerDelegate::CreateLambda([&]()
{
Widget->RemoveFromParent();
}), WaitTime, false);
블루프린트의 Delay 기능을 SetTimer를 사용해서 구현할 수 있음
+)
하얀 네모가 생기면서 언리얼 에디터 뷰포트 창이 잠겼을 때
https://forums.unrealengine.com/t/viewport-locked/217697
Viewport locked?
Hey guys, First of all, it’s my first time using this forum so I hope I’m somewhat in the right category. (). Please move the Thread if not. I’m very new to Unreal and basically don’t have a real plan of what I’m doing yet so it happened, that I
forums.unrealengine.com
껐켰하거나
브라우저나 출력 탭... 여튼 다른 공간에서 뷰포트로 드래그 하면 풀린다는듯
두번째 방법은 안 해봐서 모르겠고 확실한 건 1번 ㅋㅋ