Yet another question about network replication.
So far in my project, simple variable replication like the following hasn’t been a problem:
.h
UPROPERTY(Replicated)
int32 networkId;
.cpp
void APuzzleBlankBlock::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
DOREPLIFETIME(APuzzleBlankBlock, networkId);
}
Whenver I run this with 4 Players I can see that the client’s variable will be set to the server’s value, whenever that server changes it. Perfect.
Seemingly unrelated to this, my Actor can also replicate it’s movement and rotation, however much easier, through setting the inherited “bReplicatesMovement” field to true. This, also,
works like a charm on its own. The Actor in both cases is obviously set to “bReplicates = true” as well, and appears in all other clients’ viewports.
However, combining these too stops the movement and rotation from being replicated alltogether, all Actor’s are still visible, barely moved away from their spawn, and
not moving at all. The replicated variable “networkId” continues to work. I do have the suspicion that the DOREPLIFETIME is used to replicate the movement and
rotation as well, since that’s how I would do it if I didn’t have the simple boolean, so I might be overwriting the code that replicates these. I imagine there’s a replication of the
location Vector and the rotation Rotator with both having a RepNotify with setting these variables when changed. But I am too noob to find the exact setup that lets me
have both variable replication and automatic movement/rotation replication. I imagine this problem must have come up rather often, but I couldn’t find anything in the forums either.
Any tips on this would be greatly appreciated, my project deadline is coming up and I’d hate to spend time on coding location/rotation replication from hand.
Cheers!
EDIT: SOLUTION
GetLifetimeReplicatedProps needs to call it’s super even though this is barely mentioned anywhere! Be aware!
void AActorClass::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AActorClass, yourVariableToBeReplicated );
}
Thanks again to everyone being incredibly helpful.