Onrep not running on server?

Isn’t the Onrep function(Cpp btw) supposed to run in both on client and server? I thought it was supposed to take care of simple variable replication, but I can’t seem to get it working on the server side, and have to make separate functions for all of them, which seems unnecessary. Am I missing something?

Here’s my code, can I simplify it?:


void APlayerCharacter::SetIsDead(bool value) { // for ease of use
	if (HasAuthority()) {
		SetIsDead_Server(value);
	}
	else {
		SetIsDead_Client(value);
	}
}

void APlayerCharacter::SetIsDead_Client_Implementation(bool value) // client, reliable
{
	SetIsDead_Server(value);
}

void APlayerCharacter::SetIsDead_Server_Implementation(bool value) /* server, reliable, why doesn''t it work without this? */
{
	bIsDead = value;
	RetargetMesh->SetSimulatePhysics(value);
}

void APlayerCharacter::OnRep_IsDead() // bool IsDead , replicatedusing = onrep_isdead
{
	RetargetMesh->SetSimulatePhysics(value);
}

No. Blueprint is the exception where it also calls RepNotify on the server itself.

Replication is something that happens on clients triggered by the server when changing a replicated variable.

You can get the Blueprint RepNotify behavior in cpp by calling OnRep when you change the variable on the server.

void APlayerCharacter::KillPlayerCharacter()
{
	if (HasAuthority())
	{
		bIsDead = true;
		OnRep_IsDead();
	}
}

void APlayerCharacter::OnRep_IsDead()
{
	RetargetMesh->SetSimulatePhysics(bIsDead);
}

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