ReplicatedVar won't replicate

I have checked my code against final version in the lecture and deleted Binaries, Intermediate and Saved folders and restarted/rebuilt the project, however the ReplicatedVar will not replicate.

It is updated properly (in/from the listen server only), but the client does not pick up the change.

Only error in the output log is:

LogPackageName: Warning: DoesPackageExist called on PackageName that will always return false. Reason: Input ‘’ was empty.

class MULTIPLAYER_API AMyBoxActor : public AActor
{
// …
UPROPERTY(Replicated, BlueprintReadWrite) float ReplicatedVar;
void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override;
};

AMyBoxActor::AMyBoxActor()
{
PrimaryActorTick.bCanEverTick = true;
bReplicates = true;
ReplicatedVar = 100.f;
}

void AMyBoxActor::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AMyBoxActor, ReplicatedVar);
}

Solved it myself. I used

SetReplicates(true);

instead of bReplicates = true in constructor it now it works.

1 Like

Can you confirm the version of unreal you used? The bReplicates worked fine with me in 5.2 so wondering if this is a change in 5.3

Version: 5.2.1-26001984+++UE5+Release-5.2

Just to confirm, I commented out SetReplicates(true) in BeginPlay() and added back bReplicates = true in the constructor. As I expected, it no longer worked.

Here is some further testing I did using GetIsReplicated() in case it proves helpful:

I found that GetIsReplicated() returns false in BeginPlay() (for both client and server) when I use bReplicates = true in ctor, while the same function returns true in the ctor for both server and client in this scenario.

However, when using SetReplicates(true) in BeginPlay(), GetIsReplicated() returns true for the server and false for the client.

1 Like

Hi,
I am going through issues and looked further into the bReplicates vs SetReplicates and found the issue. With bReplicates and SetReplicates, both work equally well but I found when I hit the problem, close the Unreal Editor, build in code editor and open the project and it works. Had issues replicating a component. I tried both as I remember you mentioning this. This was in 5.2.x so can’t vouch for it being the same in 5.3 as I’ve not even tested that version yet - too PC intensive.

Thought I’d share this anyway.

Thanks. If it doesn’t make a difference, I guess I’ll just stick to using SetReplicates then.

1 Like

Yeah, no difference. Honestly I’d use Set Replicates normally but when following courses I support I try and stick to the source provided to be sure it all works.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms