Download

Server RPC executes parts on server and parts on client?

Just as I thought I had mastered RPCs, I’ve been thrown a curve. I have this function that is a Server RPC



bool AShooterCharacter::DropEnergyPack_Validate()
{
return true;
}

void AShooterCharacter::DropEnergyPack_Implementation()
{
if(!myEnergyPack)
{
return;
}

myEnergyPack->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
myEnergyPack->energyPackBody->SetSimulatePhysics(true);
myEnergyPack->boxCollider->SetSimulatePhysics(true);

myEnergyPack = nullptr;
}


What happens here is, that myEnergyPack detaches from the character on ALL instances (server and all clients), but only falls down on the server, and remains suspended in air on the clients. I understand that this function is only supposed to execute on the server so simulate physics turning true only on the server is understandable, but then why does it detach on all clients? And what other things can automatically propagate to the clients like detachment does in this case ?

Attachment is replicated in the Actor class.

You can find all replicated properties in the function GetLifetimeReplicatedProps:



DOREPLIFETIME_WITH_PARAMS_FAST(AActor, bReplicateMovement, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, Role, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, RemoteRole, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, Owner, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, bHidden, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, bTearOff, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, bCanBeDamaged, SharedParams);
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, Instigator, SharedParams);

FDoRepLifetimeParams AttachmentReplicationParams{COND_Custom, REPNOTIFY_Always, /*bIsPushBased=*/true};
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, AttachmentReplication, AttachmentReplicationParams);

FDoRepLifetimeParams ReplicatedMovementParams{COND_SimulatedOrPhysics, REPNOTIFY_Always, /*bIsPushBased=*/true};
DOREPLIFETIME_WITH_PARAMS_FAST(AActor, ReplicatedMovement, ReplicatedMovementParams);