I want to use LineTraceSingleByChannel function for my SightRay component which will be used for my adventure game. I want to mark certain objects in game as 'Viewable' in Trace Channel. Then the ray will only be true if it hits a 'Viewable' object.
I have created the Viewable trace channel in the Collision settings of Project Settings. But I have two problems now.
In the actual c++ code I am writing, how do I reference this new 'Viewable' channel in the ECollisionChannel parameter of the method?
How do I assign this channel to each object in the scene?
I have been trying to figure this out for hours, I've read many Unreal documentation pages and forum threads but can't get a straight answer, particularly without using Blueprint nodes.
Here is my code:
bool USightRay::GetLineTraceHit(FHitResult &OutHit)
{
FVector LineStart = UGameplayStatics::GetPlayerCameraManager(this, 0)->GetCameraLocation();
FVector LineEnd = LineStart + UGameplayStatics::GetPlayerCameraManager(this, 0)->GetCameraRotation().Vector() * LineTraceLength;
//ECollisionChannel viewable = WHAT CAN I PUT HERE?????
if (GetWorld()->LineTraceSingleByChannel(OutHit, LineStart, LineEnd, viewable))
{
UE_LOG(LogTemp, Warning, TEXT("HIT ME WITH YOUR RHYTHM STICK!"));
return true;
}
return false;
}
I actually thought this would be simple before I started to code it. I've used it before but I just used ECollisionChannel::ECC_Visibility in place of 'viewable'. This time I want to learn to filter the collisions and traces properly.
Thank you for any help.