I’m sure I’m missing something here, hopefully someone can spot it. I’m trying to spawn a projectile so that it appears on both the server and the clients. At the moment I can see it being spawned on the server (listen server), but it’s not replicated to the clients. Here’s my code:
Code in my pawn to spawn on the server:
.h
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Custom)
TSubclassOf<ALinearProjectile> FireOneProjectile;
UFUNCTION(Reliable, Server, WithValidation)
void ServerSpawnProjectileOne();
virtual void ServerSpawnProjectileOne_Implementation();
virtual bool ServerSpawnProjectileOne_Validate();
.cpp
void APlayerPawnCombat::FireOne()
{
ServerSpawnProjectileOne();
}
void APlayerPawnCombat::ServerSpawnProjectileOne_Implementation()
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, FString("FireONE! ") + GetName() + FString(" : ") + FString::FromInt(Role));
ALinearProjectile* NewActor = GetWorld()->SpawnActor<ALinearProjectile>(FireOneProjectile, GetActorLocation(), GetActorRotation());
if (!NewActor)
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, FString("Spawn FAILED"));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString("Spawn OK at ")+NewActor->GetActorLocation().ToString());
}
}
bool APlayerPawnCombat::ServerSpawnProjectileOne_Validate() { return true; }
And here’s the constructor for my projectile:
ALinearProjectile::ALinearProjectile(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
StaticMeshComponent = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("StaticMesh"));
//StaticMeshComponent->AttachParent = RootComponent;
RootComponent = StaticMeshComponent;
bReplicates = true;
bAlwaysRelevant = true;
bReplicateMovement = true;
bOnlyRelevantToOwner = false;
//bStaticMeshReplicateMovement = true;
SetRemoteRoleForBackwardsCompat(ROLE_SimulatedProxy);
}
bool ALinearProjectile::IsNetRelevantFor(const APlayerController* RealViewer, const AActor* Viewer, const FVector& SrcLocation) const
{
return true; // ALWAYS RELEVANT
}
Can anyone see what I’m doing wrong?