In this lesson, you will learn how to reduce network overhead by restricting which players receive updates for specific actors based on spatial proximity.
Understanding Network Relevance
By default, Unreal Engine attempts to replicate every networked actor to every connected client. In a large world, this creates massive bandwidth waste, as players in one corner of the map do not need to know the state of a treasure chest or decorative prop located kilometers away. Optimizing Network Relevance ensures that the server only sends updates to clients who are actually close enough to perceive the actor.
The Role of Net Cull Distance
The most direct way to control this is via NetCullDistanceSquared. This value defines a sphere around the actor; if a player’s pawn is outside this range, the server will stop replicating that actor’s properties and RPCs to that specific client.
You can set this in the actor's constructor:
AMyPropActor::AMyPropActor()
{
// Set the cull distance to 50 meters (5000 units)
NetCullDistanceSquared = 5000.f * 5000.f;
// Ensure the actor is set to replicate
bReplicates = true;
}
Implementing Custom Relevance Checks
Sometimes distance isn't enough; perhaps you only want an actor to be relevant if it is within a player's line of sight or inside a specific room. You can override IsNetRelevantFor in your actor class to implement custom logic. This function is called by the server to determine if a specific connection should receive an update for this actor.
bool AMyActor::IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const
{
// Always replicate if the actor is owned by the player
if (GetOwner() == ViewTarget) return true;
// Add custom logic: only replicate if within a specific gameplay volume
return Super::IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation) && IsInsideActiveZone();
}
By combining NetCullDistanceSquared for general performance and IsNetRelevantFor for granular gameplay requirements, you prevent the server from wasting precious bandwidth on invisible or irrelevant data.
Key Takeaway: Restricting network relevance via cull distances and conditional overrides significantly reduces packet congestion by ensuring clients only receive data for actors that are spatially or contextually meaningful to them.