When you think you’re starting to understand Replication and getting things to work you get a big fat “Nope” I have been reading a lot of stuff about replication, especially the unreal engine 3 replication documentation (it’s more complete, although some of it is not applicable to UE 4, but the core is the same). I was hoping you could help me clarify some doubts that i have right now and that i will have while i try to learn it:
-
I noticed that each client has a copy with authority of every replicated actor, but i though that copy was only for storing the latest values from the server before updating the proxy version. Today i noticed that a client also runs Server functions, so can you clarify exactly what really happens when you call a Server function? Does he execute it on both the “real” server and “copy” server?
-
What is the right way of handling the replication workflow? I have been using the following (Equip weapon pseudo code example):
void OnPressedEquipKey()
{
AWeapon * WeaponToEquip = GetWeaponToEquip();
ServerEquipWeapon(WeaponToEquip);
}
void ServerEquipWeapon(AWeapon * Weapon)
{
StartEquippingWeapon(Weapon);
ClientStartEquippingWeapon(Weapon); // Multicast to make clients do the animation also and update the current weapon
}
void ClientEquipWeapon(AWeapon * Weapon)
{
StartEquippingWeapon(Weapon);
}
void StartEquippingWeapon(AWeapon * Weapon)
{
PendingWeapon = Weapon;
PendingWeapon ->AttachRootComponentTo(Mesh, "RightHand", EAttachLocation::SnapToTarget);
float Duration = 0.1f;
if (EquipAnimMontage != NULL)
Duration = FMath::Max<float>(PlayAnimMontage(EquipAnimMontage ), 0.1f);
GetWorldTimerManager().SetTimer(this, &AMyCharacter::FinishedEquippingWeapons, Duration);
}
void FinishedEquippingWeapons()
{
CurrentWeapon = PendingWeapon;
PendingWeapon = NULL;
}
Is this the right way? I’ve been using this Server function executes a function then calls the Client function that executes the function again and i haven’t used repnotify for anything. Are there conventions to properly replicate things? Because i’m getting the feeling that i’m not doing things the way it was designed by Epic.