OnReplicated Functions Question for ListenServer?

Okay, I have some basic networking questions. I was under the impression that the ListenServer would run both the server and client functions, but it really doesn’t. Here is an example.

In my game, the player has the choice to join a dedicated server or to host their own game as Listen Server.

//Level of unit Variable used for Replication
UPROPERTY(replicatedUsing = OnRep_m_iUnitLevel)

uint8 m_iUnitLevel;

…Gain enough experience on the server to level

Example::OnLevelUp()
{

m_iUnitLevel++; //Increase the level by one

}

//On the replicated function I want to call the particle effect showing a level up on the client
Example::OnRep_m_iUnitLevel()
{
Emit Levelup Particles
}

This will work only for the pureclients and not the listenserver player. Is the fix just to check for Net_ListenServer and manually run “OnRep_m_iUnitLevel()” from the server?

I’m trying to save as much bandwith as possible so I combine where I can. I’m already sending down the unitlevel, but I don’t want to also send down a RPC also for the particles. However, I want the ListenServer player to see the particles also, but not if its a dedicated server.

Hopefully I stated that clearly. Any suggestions on this? Thanks!

A typical pattern for OnRep calls here is to make sure that the server calls it at the site of the variable change.

void ChangeSomeStuff()
{
   myReplicatedVar = newValue;
   if (Role == ROLE_Authority)
   {
     OnRep_myReplicatedVar()
   }
}

That way you have one code path for the replication event and all clients/server get the change.

Thanks, that is what I was doing temporarily, now I know its a good solution. :slight_smile:

For those looking for an easier way to check for the ListenServer

GetNetMode() == NM_ListenServer