Last active
May 28, 2019 16:35
-
-
Save whoo24/c8da40cda78f8cada5e144e3164f3262 to your computer and use it in GitHub Desktop.
Is an actor in frustum in UE4?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool IsInFrustum(AActor* Actor) | |
{ | |
ULocalPlayer* LocalPlayer = Actor->GetWorld()->GetFirstLocalPlayerFromController(); | |
if (LocalPlayer != nullptr && LocalPlayer->ViewportClient != nullptr && LocalPlayer->ViewportClient->Viewport) | |
{ | |
FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues( | |
LocalPlayer->ViewportClient->Viewport, | |
Actor->GetWorld()->Scene, | |
LocalPlayer->ViewportClient->EngineShowFlags) | |
.SetRealtimeUpdate(true)); | |
FVector ViewLocation; | |
FRotator ViewRotation; | |
FSceneView* SceneView = LocalPlayer->CalcSceneView(&ViewFamily, ViewLocation, ViewRotation, LocalPlayer->ViewportClient->Viewport); | |
if (SceneView != nullptr) | |
{ | |
return SceneView->ViewFrustum.IntersectSphere(Actor->GetActorLocation(), Actor->GetSimpleCollisionRadius()); | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment