Hi Guys
I’ve followed along with Ben and refactored, but the code doesn’t compile because it doesnt like the calls to GetReachLineStart() and GetReachLineEnd() in the LineTraceSingleByObjectType() method in GetFirstPhysicsBodyInReach()
Here are the relevant methods my code:
grabber.cpp
FHitResult UGrabber::GetFirstPhysicsBodyInReach() const
{
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());
FHitResult HitResult;
GetWorld()->LineTraceSingleByObjectType(
OUT HitResult,
GetReachLineStart(), // This is underlined in red
GetReachLineEnd(), // This is underlined in red
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
TraceParameters
);
return HitResult;
}
FVector UGrabber::GetReachLineStart()
{
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);
return PlayerViewPointLocation;
}
FVector UGrabber::GetReachLineEnd()
{
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);
return PlayerViewPointLocation + (PlayerViewPointRotation.Vector()*Reach);
}
And the header file
grabber.h
FHitResult GetFirstPhysicsBodyInReach() const;
FVector GetReachLineStart();
FVector GetReachLineEnd();
And the errors I’m getting are:
VS
the object has type qualifiers that are not compatible with the member function “UGrabber::GetReachLineStart”
Unreal
error C2662: ‘FVector UGrabber::GetReachLineStart(void)’: cannot convert ‘this’ pointer from ‘const UGrabber’ to ‘UGrabber &’
The references to those methods in GetWorld()->LineTraceSingleByObjectType seem to be the problem. I looked at Ben’s code in GitHub and it seems to be the same. Can anyone suggest what the problem miught be?
Cheers
Lucas