Hi everyone,
I am just starting with replication and dedicated server architecture. I have a custom pawn class which is used as a base for planets put in the game. I have a loop that ticks every second which calls methods responsible for the movement of the planet around itself and around it’s sun. What I want to achieve is this. The loop should be called on the server only and then the new location of the planet to be replicated to all the clients. What I did try was this:
.h
UFUNCTION()
void UpdateActor(float dt);
UFUNCTION(Reliable, Server, WithValidation)
void Server_UpdateActor(float dt);
virtual void Server_UpdateActor_Implementation(float dt);
virtual bool Server_UpdateActor_Validate(float dt);
.cpp
// Called every frame
void ATC_SO_PlanetBase::Tick(float dt)
{
Super::Tick(dt);
Server_UpdateActor(dt);
}
bool ATC_SO_PlanetBase::Server_UpdateActor_Validate(float dt)
{
return true;
}
void ATC_SO_PlanetBase::Server_UpdateActor_Implementation(float dt)
{
if (Role == ROLE_Authority)
{
GetCurrentWorldRotation(dt);
GetCurrentLocalRotation(dt);
SetLocation(dt);
SetWorldRotation(dt);
SetLocalRotation(dt);
}
}
I also checked the following properties in the editor: Replicates, Replicated Movement, Always Relevant. Can someone explain how should I achieve this. Any help would be appreciated. If the other part of the code is needed I will post it.