Download

RPC not being called

Like the title says, for some reason my RPC isn’t being called. I’ve made a couple posts on reddit for this but hardly anyone there seems to want to help out much.



UPROPERTY(VisibleAnywhere,ReplicatedUsing= OnRep_Weapon , Category = Weapon)
class AWeapon* Weapon;

void AFPSCharacter::OnRep_Weapon()
{
UE_LOG(LogTemp, Warning, TEXT("OnRep_Weapon() called"))
OnUpdateWeapon();
}

void AFPSCharacter::OnUpdateWeapon()
{
Weapon->SetOwningPawn(this);

Weapon->EquipToPlayer(this);
}


void AFPSCharacter::Fire()
{
ServerFire();
if (FireAnimation)
{
// Get the animation object for the arms mesh
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance)
{
AnimInstance->Montage_Play(FireAnimation, 1.0f);
}
}

}

void AFPSCharacter::ServerFire_Implementation()
{
UE_LOG(LogTemp, Warning, TEXT("ServerFire() called"))
if (Weapon) {
Weapon->Fire();
Fire();
}
}

void AWeapon::EquipToPlayer(AFPSCharacter* NewOwner)
{
SetOwner(NewOwner);
SetInstigator(NewOwner);
OwningPawn = NewOwner;

if (GunMesh) {
FAttachmentTransformRules AttachRules(EAttachmentRule::KeepRelative, true);
GunMesh->AttachToComponent(NewOwner->GetMesh1P(), AttachRules, NewOwner->GetWeaponSocket());
}
}

void AWeapon::Fire()
{
if (GetLocalRole() == ROLE_Authority)
{
UE_LOG(LogTemp, Warning, TEXT("Pawn is Authority, calling ServerFire()"));
ServerFire();
}

if (FireSound)
{
UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
}
}

void AWeapon::ServerFire_Implementation()
{
UE_LOG(LogTemp, Warning, TEXT("ServerFire() called"));
// try and fire a projectile
if (ProjectileClass != nullptr)
{
UWorld* const World = GetWorld();
if (World != nullptr)
{
FRotator SpawnRotation;
// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
FVector SpawnLocation;

GetOwner()->GetActorEyesViewPoint(SpawnLocation, SpawnRotation);

//Set Spawn Collision Handling Override
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
ActorSpawnParams.Owner = this;
ActorSpawnParams.Instigator = GetInstigator();

// spawn the projectile at the muzzle
auto ptr = World->SpawnActor<AProjectile>(ProjectileClass, SpawnLocation, SpawnRotation, ActorSpawnParams);
if (ptr == nullptr) {
UE_LOG(LogTemp, Warning, TEXT("Projectile could not be spawned"));
}
else {
UE_LOG(LogTemp, Warning, TEXT("Projectile spawned at: %i, %i, %i"), SpawnLocation.X, SpawnLocation.Y, SpawnLocation.Z);
}
}
}
}


For some reason if BindAction is set to use AFPSCharacter::ServerFire() I get a navmesh cannot be 0 error or something like that, but no error. The RepNotify does get called so the weapon should be replicated but the implementation for AWeapon::ServerFire() never gets called. Can anyone help me figure out what’s going on here? Or point me in the right direction?