Stopping actor deletion when outside of Network Cull Distance on clients?

I found it in 5.3 source code but have no idea when it was added sorry.

After double checking, it looks like the delegate and methods are protected, so using them will be a bit more difficult unfortunately. Sounds like you’d have to create your own UNetDriver subclass, but then you could override the relevant methods directly, which makes the delegate kinda redundant…

I’ve seen your other post but not had the time to dig into it yet. I can already say that in the traditional replication framework, ForceNetUpdate will not override the Priority sorting, so if you call ForceNetUpdate and return 0 in GetNetPriority, chances are it’s not gonna update. ForceNetUpdate only overrides the Frequency setting. Regardless, I think the method 1 is pretty solid anyways, and you could easily add a variable(+method) similar to ForceNetUpdate, that you’d check in your GetNetPriority function if you want to force-update. The problem about initial replication and AlwaysRelevant is a good point that will require some more digging. The first idea I can come up with is to override IsNetRelevantFor to keep the actor irrelevant until it’s supposed to be relevant, but only if the actor has not been relevant yet, so also gotta keep track of who it’s been replicated to… :roll_eyes:
It’s a bit convoluted but I don’t see any reason why it wouldn’t work…

UPROPERTY()
TSet<AActor*> RelevanceSet;

bool AMyActor::IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const
{
    if (!RelevanceSet.Contains(RealViewer))
    {
        if (!IsWithinNetRelevancyDistance(ViewLocation))
            return false;  //never been relevant yet

        RelevanceSet.Emplace(RealViewer, true);
    }
    return true; //always relevant
}

Ideally though, I’d like to dig into the netdriver code to see if it’s possible to access the replication channels to check if one already exists for that player or not.

Alternatively, again, subclassing the NetDriver might make things easier. I hadn’t suggested it at first, but if you do it, you could also attempt to override the method and simply not close the channel if the actor is an actor of your specific class…

1 Like