I’m experiencing some very strange behavior with replication while using a listen server and one additional client (for a total of two players), so I suspect that my understanding of replication in UE4 is somewhat flawed. To illustrate this, I have setup the following conditions (for the sake of simplicity, I will call the player who is running the listenServer player1, and I will call the player who is connecting to the listen server player2):
-in Player class (which extends ACharacter):
UPROPERTY(replicated) bool testvar = false;
UFUNCTION(Server, Reliable) void ServerSetTestvar(ASurvivalGameCharacter* player);
-in Player OnFire:
ServerSetTestvar(this);
-in Player Tick:
if (testvar)
Util::disp(this, "TESTVAR SET"); // custom screen print method
-ServerSetTestvar definition:
void ASurvivalGameCharacter::ServerSetTestvar_Implementation(ASurvivalGameCharacter* player) {
player->testvar = true;
}
In short, I have a boolean that I expect to print a statement repeatedly once it is set to true.
I tested this code under two circumstances:
- With no replication condition set for testvar in GetLifetimeReplicatedProps
- With testvar set to COND_SkipOwner in GetLifetimeReplicatedProps:
DOREPLIFETIME_CONDITION(ASurvivalGameCharacter, testvar, COND_SkipOwner);
For the first test (no replication condition):
Expectation:
-Upon triggering OnFire as player1: the real player1 on the host will print TESTVAR SET, and the simulated player1 on the client will also print TESTVAR SET
-Upon triggering OnFire as player2: the real player2 on the client will print TESTVAR SET, and the simulated player2 on the host will also print TESTVAR SET
Actual Result:
-Upon triggering OnFire as player1: only the real player1 on the host prints TESTVAR SET
-Upon triggering OnFire as player2: only the simulated player2 on the host prints TESTVAR SET
For the second test (COND_SkipOwner):
Expectation:
-Upon triggering OnFire as player1: only the simulated player1 on the client will print TESTVAR SET
-Upon triggering OnFire as playerr2: only the simulated player2 on the host will print TESTVAR SET
Actual Result:
-Upon triggering OnFire as player1: the real player1 on the host prints TESTVAR SET, and the simulated player1 on the client also prints TESTVAR SET
-Upon triggering OnFire as player2: only the simulated player2 on the host prints TESTVAR SET
As you can see, my expectations for variable replication do not match the actual results of my tests. What’s particularly unexpected is that COND_SkipOwner seemingly causes the host to replicate to the simulated player1, whereas I would strictly expect COND_SkipOwner to cause fewer replications.
Can anyone shed some light onto this issue? I feel like I must be misunderstanding something fundamental about replication in UE4, and have been racking my brain over this for some time now. Any help would be greatly appreciated.