alright so what i want do is raycast into the world and try to reach actors that have a specific tag and if the tag matches I wanna display an image on the screen. this kinda works except that its not consistent all the time sometimes the image shows up sometimes it doesn’t whats wrong here that I don’t get?
also I’m calling the function in the tick.
void AMain:DetectItems()
{
FVector Location = FirstPersonCameraComponent->GetComponentLocation();
FVector End = (FirstPersonCameraComponent->GetForwardVector() * CastingRange) + Location;
FHitResult Hit;
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);
GetWorld()->LineTraceSingleByChannel(Hit, Location, End, ECollisionChannel::ECC_Visibility, Params);
DrawDebugLine(GetWorld(), Location, End, FColor::Red, false, .3f);
if (Hit.GetActor())
{
bool HitResult = Hit.GetActor()->ActorHasTag(TEXT(“InteractableItems”));
if (HitResult && !InteractCrosshair->IsInViewport())
{
InteractCrosshair->AddToViewport();
}
else if (InteractCrosshair->IsInViewport())
{
InteractCrosshair->RemoveFromViewport();
}
}
}