Yeah that fixed the problem, thanks man, but now it crashes when i interact and constantly calls show/hide prompt when looking at the object
void APlayerCharacter::Interact() // Interacts
{
if (CurrentInteractableActor)
{
if (CurrentInteractableActor->Implements<UInteract_Interface>())
{
IInteract_Interface::Execute_Interact(CurrentInteractableActor, this);
}
else
{
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("INTERACT - CurrentInteractableActor is NOT valid"));
}
}
void APlayerCharacter::CheckForInteractable()
{
FVector Start = Camera->GetComponentLocation();
FVector ForwardVector = Camera->GetForwardVector();
FVector End = Start + (ForwardVector * InteractionRange);
FHitResult HitResult;
FCollisionQueryParams TraceParams(FName(TEXT("InteractTrace")), false, this);
// Check if the previously interacted object is still in focus, and hide its prompt if not
if (CurrentInteractableActor)
{
UE_LOG(LogTemp, Warning, TEXT("CURRENTINTERACTABLE"));
if (CurrentInteractableActor->Implements<UInteract_Interface>())
{
IInteract_Interface::Execute_HideInteractionPrompt(CurrentInteractableActor);
UE_LOG(LogTemp, Warning, TEXT("HIDEPROMPT"));
}
CurrentInteractableActor = nullptr;
}
if (GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Visibility, TraceParams))
{
// Check if the hit actor implements the InteractableInterface
AActor* HitActor = HitResult.GetActor();
UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *HitActor->GetName());
UE_LOG(LogTemp, Warning, TEXT("Hit Location: %s"), *HitResult.ImpactPoint.ToString());
if (HitActor->Implements<UInteract_Interface>())
{
// Display interaction prompt
IInteract_Interface::Execute_ShowInteractionPrompt(HitActor);
CurrentInteractableActor = HitActor; // Update the current interactable object
UE_LOG(LogTemp, Warning, TEXT("SHOWPROMPT"));
}
}
}
i tried using do once before but i dont know how to properly use it, it seems to form an infinite loop when interacting.