multiplayer. how does IsNetRelevantFor function work??

im trying to control the way how clients replicate to other clients. I’m level streaming maps and i dont want to replicate for clients not are not in the same map. I came across this function but i have no idea how it works? anyhelp?? Thanks!

IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation)

As far as i understand you can check if a actor is relevant for replication.
Now in the Replication category in your Actor you can set the distance from witch this actor will replicate to the client.

the problem with this method is that if there is an actor not in the same level stream but within the same replicating distance, that actor will get replicated and look like its floating in the air doing non-sense. I need to create a way that where all the relavent actors in the same level stream will only replicate to each other, and any other actors outside that level stream will not get replicated.

I guess you could do a conditional replication of the values / actor.
Depending on your conditions are met.

How would i do that?? Sorry, im still learning the ins and outs of networking?? thanks!!

I would start Network Tips and Tricks - Unreal Engine
It will explain conditional replication for you in detail.

You could do conditions for all values or do some clever check in


GetLifetimeReplicatedProps( TArray< FLifetimeProperty > & OutLifetimeProps ) const

And only replicate when apropriate.

Hope it helps
.

Hello everyone sorry for the long delay in response. So is what I did…

In your Character class you have a virtual function ’ IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) ’

You want to over load that. RealViewer refers to the player controller, and ViewTarget refers to the Character. These are what you are doing checks on for relevancy and it’s done on the Server side.

In the cpp of your character class, you first want to do a check of a condition that it must absolutely pass. In my case it was to check if the ViewTarget, or Character, was in the same level as me.

After that, if it passed the first check, you should then call the Super for the regular check. is my code

bool YourCharacter::IsNetRelevantFor(const AActor* RealViewer, const AActor* ViewTarget, const FVector& SrcLocation) const
{
if (Cast<YourCharacter>(ViewTarget)->CurrentLevelStream == CurrentLevelStream)
return Super::IsNetRelevantFor(RealViewer, ViewTarget, SrcLocation);
else
return false;
}

you can do other stuff. I just did a check to see if other players were in the same level stream as me. Anyways thanks for the help and good luck to everyone else!

3 Likes

I know this is from almost a decade ago, did you have to add anything to the .h file?

I’m using a blueprint project but created a new C++ class based on the character class.

I’ve added the above code, modified the check that I need for my game but get a

"‘IsNetRelevantFor’: member function not declared in ‘ACharacter_IsNetRelevantOvr’ error.

What am I missing?