APawn::IsNetRelevantFor
#include "GameFramework/Pawn.h"
Access: public
Specifiers: virtualoverride
Description
Determines whether this pawn should be replicated to a given viewer. APawn overrides the default actor logic to also return true when the pawn is the viewer's ViewTarget, ensuring spectated pawns are always considered relevant.
Caveats & Gotchas
- • Returning true from this override guarantees the actor is replicated but does not bypass NetCullDistanceSquared — the server still drops actors beyond the cull distance. Override both this and NetCullDistanceSquared if you need truly always-relevant pawns.
- • Called per-actor per-connection every replication frame on the server, so keep any override extremely cheap — no physics queries, no asset loads.
- • If you override this in a subclass, also check bAlwaysRelevant and bOnlyRelevantToOwner flags from the parent implementation to avoid silently disabling Epic's built-in relevancy rules.
Signature
virtual bool IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const override Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| RealViewer | const AActor* | The actor performing the relevancy check, usually a PlayerController. | — |
| ViewTarget | const AActor* | The actor currently being viewed by RealViewer (the ViewTarget of the PlayerController). | — |
| SrcLocation | const FVector& | World location of the viewer, used for distance-based relevancy. | — |
Return Type
bool Example
Force teammates to always be relevant within a radius C++
bool AMyPawn::IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const
{
if (Super::IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation))
{
return true;
}
// Also keep teammates relevant within a large radius for minimap etc.
if (IsSameTeam(RealViewer))
{
return FVector::DistSquared(GetActorLocation(), SrcLocation) < FMath::Square(10000.f);
}
return false;
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?