Hello,
I’m pretty new with the ue4 networking,so I am wondering if there is another way to do a simple communication between a client and a server that should do the same thing(to execute a function on both server and client without considering where is called).Right now i’ve succeeded doing two functions rpc (one for server and another for client(s)) that does the same thing and treat each one when to me called (if the role is server -> call the “clients” rpc otherwise the “server and other clients” rpc).
header:
UFUNCTION(Server, Reliable, WithValidation)
void SpawnFireEffectToServer();
virtual void SpawnFireEffectToServer_Implementation();
virtual bool SpawnFireEffectToServer_Validate();
UFUNCTION(NetMulticast, Reliable)
void SpawnFireEffectToClients();
virtual void SpawnFireEffectToClients_Implementation();
.cpp where is called:
if (Role == ROLE_Authority)
SpawnFireEffectToClients();
else
SpawnFireEffectToServer();
.cpp implementations of rpc functions:
void AWeaponBase::SpawnFireEffectToServer_Implementation() {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("START FIRE ON SERVER "));
createFireEffects();
}
void AWeaponBase::SpawnFireEffectToClients_Implementation() {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("START FIRE ON CLIENT "));
createFireEffects();
}
void AWeaponBase::createFireEffects()
{
FVector Location = WeaponMesh->GetSocketLocation(MuzzleSocketName);
FRotator Rotation = WeaponMesh->GetSocketRotation(MuzzleSocketName);
UGameplayStatics::SpawnEmitterAttached(ShotEffect, WeaponMesh, MuzzleSocketName, Location, Rotation, EAttachLocation::KeepWorldPosition, true);
UGameplayStatics::PlaySoundAttached(ShotSound, WeaponMesh, MuzzleSocketName, Location, EAttachLocation::KeepWorldPosition, true, 1, 1, 0);
}
So in other words I'm not interested where the function is called(on client(s) or server), but i want to see the spawn effects on all clients and server.Also i've tried with replication the vars ShotEffect and ShotSound but it didn't work.
Any help will be really appreciated.