Currently for some odd reason the clients cannot see the projectile spawn when connected to the dedicated server. The projectile is marked as replicated as well. The weapon firing is triggering from an ActorComponent.
UFUNCTION(BlueprintCallable, Category="Weapon")
void Fire();
void SpawnProjectile(FVector Location, FRotator Rotation);
UFUNCTION(Server, Reliable, WithValidation)
void Server_SpawnProjectile(FVector Location, FRotator Rotation);
void Server_SpawnProjectile_Implementation(FVector Location, FRotator Rotation);
bool Server_SpawnProjectile_Validate(FVector SpawnLocation, FRotator SpawnRotation);
...
void UTP_WeaponComponent::Fire()
{
if (Character == nullptr || Character->GetController() == nullptr)
{
return;
}
// Try and fire a projectile
if (ProjectileClass != nullptr)
{
APlayerController* PlayerController = Cast<APlayerController>(Character->GetController());
const FRotator SpawnRotation = PlayerController->PlayerCameraManager->GetCameraRotation();
const FVector SpawnLocation = GetOwner()->GetActorLocation() + SpawnRotation.RotateVector(MuzzleOffset);
SpawnProjectile(SpawnLocation, SpawnRotation);
}
}
...
void UTP_WeaponComponent::SpawnProjectile(FVector Location, FRotator Rotation)
{
if (GetOwner()->HasAuthority())
{
UWorld* const World = GetWorld();
if (World != nullptr)
{
//Set Spawn Collision Handling Override
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
// Spawn the projectile at the muzzle
World->SpawnActor<ATP_FirstPersonProjectile>(ProjectileClass, Location, Rotation, ActorSpawnParams);
}
}
else
{
Server_SpawnProjectile(Location, Rotation);
}
}
void UTP_WeaponComponent::Server_SpawnProjectile_Implementation(FVector SpawnLocation, FRotator SpawnRotation)
{
SpawnProjectile(SpawnLocation, SpawnRotation);
}
bool UTP_WeaponComponent::Server_SpawnProjectile_Validate(FVector SpawnLocation, FRotator SpawnRotation)
{
return true;
}