I just got into networking and i figured some things out but some others not.
I have this pawn that moves. It has a UFloatingPawnMovementComponent. I want to replicate the movement (position basically) on all clients.
This is not working and i don’t know why. I’ll show you my code.
In the header file:
UPROPERTY(EditAnywhere, Replicated)
UStaticMeshComponent* birdMesh;
UPROPERTY(EditAnywhere, Category = Movement, Replicated)
UFloatingPawnMovement* movementComp;
UFUNCTION(Server, Reliable, WithValidation)
void serverChangePawnPosition(float deltaTime);
void changePawnPosition(float deltaTime);
virtual void serverChangePawnPosition_Implementation(float deltaTime);
virtual bool serverChangePawnPosition_Validate(float deltaTime);
Now i have 2 ways to change the pawns position. By doing
movementComp->Velocity.Y = movementSpeed;
Or by using the change position function (which i probably understand wrong)
void ABird::changePawnPosition(float deltaTime)
{
FVector newBirdLoc = GetActorLocation();
newBirdLoc.Y += movementSpeed * deltaTime;
SetActorLocation(newBirdLoc, true);
if (Role < ROLE_Authority)
{
serverChangePawnPosition(deltaTime);
}
}
bool ABird::serverChangePawnPosition_Validate(float deltaTime)
{
return true;
}
void ABird::serverChangePawnPosition_Implementation(float deltaTime)
{
changePawnPosition(deltaTime);
}
But both are not replicating the pawn, and also not it’s movement. Maybe the problem starts with the fact that i dont see the other client’s mesh at all.
The way i spawn the mesh, in the pawn’s controller :
In header:
UFUNCTION(Server, Reliable, WithValidation)
void serverSpawnPawn();
void serverSpawnPawn_Implementation();
bool serverSpawnPawn_Validate();
In source file:
void ABirdController::serverSpawnPawn_Implementation()
{
FActorSpawnParameters spawnParams;
ABird* pawn = GetWorld()->SpawnActor<ABird>(ABird::staticclass(), FVector(0, 0, 0), FRotator(0, 0, 0), spawnParams);
Possess(Cast<APawn>(pawn));
}
bool ABirdController::serverSpawnPawn_Validate()
{
return true;
}
Then i call the serverSpawnPawn in the begin play function of the controller.
I also notices that Role == ROLE_Authority is true in my pawn so i must not be spawning it right