Download

C++ replication issues Drop and Pickup

Hi,
I’m having some issues with replication, in regards to pick up and drop weapon for primary and secondary
-> if I pickup a rifle, it will drop a rifle / Or handgun for a handgun

For the first step, it works perfectly fine for server and client

In character class, I have this…
-------------------------------------------------------------------------------------------BaseCharacter.h

virtual void Use();
UFUNCTION(Server, Reliable, WithValidation)
void ServerUse();
void ServerUse_Implementation();
bool ServerUse_Validate();

-------------------------------------------------------------------------------------------BaseCharacter.cpp
void ABasePlayer::Use()
{
ABaseUsableActor* Usable = GetUsableInView();
if (Usable)
{
// Only allow on server. If called on client push this request to the server
if (GetLocalRole() < ROLE_Authority)
{
ServerUse();
}
else
{
Usable->OnUsed(this);
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, “CheckServer”);
}
}
}

void ABasePlayer::ServerUse_Implementation()
{
ABaseUsableActor* UseActor = GetUsableInView();
if (UseActor)
{
UseActor->OnUsed(this);
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Blue, “CheckClient”);
}
}

bool ABasePlayer::ServerUse_Validate()
{
return true;
}


it works fine up till here, but I would like to know if this is wrong way to do it

For the second step I am trying to replicate the used function inc pickupActor class
-------------------------------------------------------------------------------------------BaseWeaponPickup.h
virtual void OnUsed(APawn* InstigatorPawn) override;

UFUNCTION(Server, Reliable, WithValidation)
void ServerOnUsed(APawn* InstigatorPawn);
void ServerOnUsedImplementation(APawn* InstigatorPawn);
bool ServerOnUsedValidate(APawn* InstigatorPawn);

UFUNCTION(Reliable, NetMulticast)
void OnUsedMulticast(APawn* InstigatorPawn);
void OnUsedMulticast_Implementation(APawn* InstigatorPawn);

-------------------------------------------------------------------------------------------BaseWeaponPickup.cpp
void ABaseWeaponPickup::OnUsed(APawn* InstigatorPawn)
{
ABasePlayer* MyPawn = Cast<ABasePlayer>(InstigatorPawn);
// Only allow on server. If called on client push this request to the server
if (MyPawn->GetLocalRole() < ROLE_Authority)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Blue, “UsedFromClient”);
ServerOnUsed(InstigatorPawn);
return;
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, “UsedFromServer”);
OnUsedMulticast(InstigatorPawn);
}
}

void ABaseWeaponPickup::ServerOnUsedImplementation(APawn* InstigatorPawn)
{
OnUsed(InstigatorPawn);
}

bool ABaseWeaponPickup::ServerOnUsedValidate(APawn* InstigatorPawn)
{
return true;
}

void ABaseWeaponPickup::OnUsedMulticast_Implementation(APawn* InstigatorPawn)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, “Used_Multicast”);
ABasePlayer* MyPawn = Cast<ABasePlayer>(InstigatorPawn);
if (MyPawn)
{
if (GetLocalRole() < ROLE_Authority)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Blue, “IsClient”);
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, “IsServer”);
}
}
}

I get compile error for the functions used as shown below…

Creating library H:\UE4_PROJECT_BACKUP\XCA\Intermediate\Build\Win64\UE4Editor\Development\XCA\UE4Editor-XCA.suppressed.lib and object H:\UE4_PROJECT_BACKUP\XCA\Intermediate\Build\Win64\UE4Editor\Development\XCA\UE4Editor-XCA.suppressed.exp
2>BaseWeaponPickup.cpp.obj : error LNK2001: unresolved external symbol “public: virtual bool __cdecl ABaseWeaponPickup::ServerOnUsed_Validate(class APawn *)” (?ServerOnUsed_Validate@ABaseWeaponPickup@@UEAA_NPEAVAPawn@@@Z)
2>BaseWeaponPickup.gen.cpp.obj : error LNK2001: unresolved external symbol “public: virtual bool __cdecl ABaseWeaponPickup::ServerOnUsed_Validate(class APawn *)” (?ServerOnUsed_Validate@ABaseWeaponPickup@@UEAA_NPEAVAPawn@@@Z)
2>BaseWeaponPickup.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl ABaseWeaponPickup::ServerOnUsed_Implementation(class APawn *)” (?ServerOnUsed_Implementation@ABaseWeaponPickup@@UEAAXPEAVAPawn@@@Z)
2>BaseWeaponPickup.gen.cpp.obj : error LNK2001: unresolved external symbol “public: virtual void __cdecl ABaseWeaponPickup::ServerOnUsed_Implementation(class APawn *)” (?ServerOnUsed_Implementation@ABaseWeaponPickup@@UEAAXPEAVAPawn@@@Z)
2>H:\UE4_PROJECT_BACKUP\XCA\Binaries\Win64\UE4Editor-XCA.dll : fatal error LNK1120: 2 unresolved externals
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ““E:\EPICGAMES\Epic Games\UE_4.24\Engine\Build\BatchFiles\Build.bat” XCAEditor Win64 Development -Project=“H:\UE4_PROJECT_BACKUP\XCA\XCA.uproject” -WaitMutex -FromMsBuild” exited with code 5. Please verify that you have sufficient rights to run this command.
2>Done building project “XCA.vcxproj” – FAILED.


I’m not that experience with replication, please let me know if you understand where I’m going wrong…