AActor::IsNetRelevantFor
#include "GameFramework/Actor.h"
Access: public
Specifiers: virtualconst
Description
Determines whether this actor is network-relevant for a given client connection. Irrelevant actors are not replicated to that client, saving bandwidth. The default implementation checks distance, always-relevant flags, and owner relevancy.
Caveats & Gotchas
- • If bAlwaysRelevant is true the default implementation short-circuits and always returns true, making this override unnecessary for most cases.
- • This is called frequently (every net update cycle) so override implementations must be cheap — avoid physics queries or iteration over large containers.
- • bOnlyRelevantToOwner causes the engine to call this only with the owning connection's viewer; overriding IsNetRelevantFor alongside bOnlyRelevantToOwner requires care to not break owner-only logic.
Signature
ENGINE_API virtual bool IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| RealViewer | const AActor* | The controlling net object (typically player controller) associated with the client for which relevancy is being checked. | — |
| ViewTarget | const AActor* | The actor used as the point of view for the RealViewer. | — |
| SrcLocation | const FVector& | The viewing location used for distance and visibility checks. | — |
Return Type
bool Example
Override to add line-of-sight check C++
bool AMyActor::IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const
{
if (!Super::IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation))
{
return false;
}
// Only replicate if within 5000 units
return FVector::DistSquared(GetActorLocation(), SrcLocation) < (5000.f * 5000.f);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?