I created a FVector2D variable in the PlayerController which holds the CrosshairRelativeLocation. I put it here because I couldn't figure out how to access the Game Level variables through the widget but the widget does have a reference to the PlayerController.
In the widget I then went to the graph and added what can be seen in the image:
Code:
bool AFirstPersonController::LineTraceSingleByChannelFromCrosshair(FHitResult& OutHit, float DistanceToCheck, ECollisionChannel TraceChannel) const { int32 ViewportSizeX, ViewportSizeY; GetViewportSize(ViewportSizeX, ViewportSizeY); FVector WorldLocation, WorldDirection; DeprojectScreenPositionToWorld(ViewportSizeX * CrosshairRelativeLocation.X, ViewportSizeY * (1.f - CrosshairRelativeLocation.Y), WorldLocation, WorldDirection); FCollisionQueryParams Params = FCollisionQueryParams(FName(TEXT("")), false, GetOwner()); if (GetPawn()) { Params.AddIgnoredActor(GetPawn()); } DrawDebugLine(GetWorld(), WorldLocation, WorldLocation + WorldDirection * DistanceToCheck, FColor::Red, true); return GetWorld()->LineTraceSingleByChannel( OutHit, WorldLocation, WorldLocation + WorldDirection * DistanceToCheck, TraceChannel, Params ); }
Edit:
So I fixed the tick thing with using On Initialized event and using Get Viewport Widget Geometry -> Get Local Size which worked just fine.
Leave a comment: