Perform Frustum Check

Hey,

What’s the best way to use the cameras frustum to check the visibility of a set of actors? Or points etc?

Been looking around but not finding anything that useful.

Thanks

1 Like

Shameless bump!

Sorry for being so obvious, but you might try tracing from each actor position to your POV (camera position), then checking if the trace was unsuccessful (nothing occludes the visibility) and it lays within the frustum cone. This is an ugly hack, I might guess, but I am not familiar with Unreal’s graphical pipeline.
If you stick to Tracing, Rama has this covered in a tutorial: https://wiki.unrealengine.com/Trace_Functions

Thanks for the info, the trace approach is an option, but all I really care about is whether or not the actors bounds are inside, intersecting or outside of the six planes of the frustum, so even if there is something in the way I’d like to know the result of that check.

You’d need to do at least two traces per actor as well since I’d need to trace to the min/max of their bounding box.

Is there anyway to actually get the planes of the camera frustum? Can just do a simple point plane check.

Will take another look when I can.

Haven’t tried it yet, but I am guessing these functions are what I want:

Will check it out, but think that’ll do it, cheers.

1 Like

You can do it like this:

bool IsInFrustum( AActor* Actor)
{
	ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
	if (LocalPlayer != nullptr && LocalPlayer->ViewportClient != nullptr && LocalPlayer->ViewportClient->Viewport)
	{
		FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
			LocalPlayer->ViewportClient->Viewport,
			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
}
7 Likes

works perfectly :smiley:

Amazing. This worked perfectly

Have a look at “WasRecentlyRendered” … it may help.

1 Like

double plus upvote

I’d love to see a Blueprint solution of the code above if anyone is up to it…

What setup/includes are needed for this to work? VS flags LocalPlayer as an incomplete class type (which I think is due to a missing include), among other errors

Sir, could you give me a blueprint’s version about this method?
Rellay need this one now :joy:


For future people.
This checks if a point is within a camera’s frustum using only blueprints.
Here is an example of it stacked within a system to choose the most optimal cctv camera.


  1. Each camera checks if each bone’s location is in its frustum.
  2. Each point in its frustum get’s line traced too.
  3. Camera with most visible points is chosen as optimal.
    …3.1. If 2 Cameras have the same amount of visible points, the one with the closest visible point wins.
    …3.2 If no camera is optimal then player camera is chosen
3 Likes