Hi there
I am trying to make an Air Hockey style game. I want to give the ‘Listen Server/Host’ the team value ‘0’ and the client the value ‘1’.
I am writing this function inside BeginPlay() on an Actor I created specially for managing the ‘Match Stats’. I have dragged this actor into my ‘Game’ map. (The process so far for clients joining the game is MAIN_MENU>LOBBY>GAME).
Anyway, I am REALLY struggling with calling a Client RPC in order to set the Team value on the client. Here is the function as I have it now, but I have tried many variants of this.
Basically my problem here stems from mallet->GetActorRole()
, it seems it always returns ROLE_AUTHORITY. So in the following example, the else
part never fires (neither on the Listen-Server instance or the Client instance).
I am clearly understanding it wrong, I figured the mallet->
part would mean it was accessing a property in that particular mallet. So I figured the ROLE_AUTHORITY would be different for the Host and for the Client.
// Called when the game starts or when spawned
void AMatchManager::BeginPlay()
{
Super::BeginPlay();
SetReplicates(true);
UWorld* World=GetWorld();
if(!ensure(World!=nullptr)) return;
if(GetWorld()->IsServer())
{
UE_LOG(LogTemp, Warning, TEXT("Match Manager BeginPlay (IS SERVER)"));
if(HasAuthority())
{
SpawnPuck();
AGameStateBase* gamestate=GetWorld()->GetGameState();
if(gamestate!=nullptr)
{
for(int i=0; i<gamestate->PlayerArray.Num(); i++)
{
APlayerMallet* mallet=(APlayerMallet*)gamestate->PlayerArray[i]->GetPawn();
if(mallet!=nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("setting team from MatchManager BeginPlay (SERVER AUTH) team will be assigned as:%d"), (i%2));
if(mallet->GetLocalRole() == ROLE_Authority)
{
UE_LOG(LogTemp, Warning, TEXT("ROLE_AUTH, so it is the listen server"));
mallet->Team=0;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("This player is client... Calling RPC"));
mallet->Client_SetTeam(i%2);
}
}
}
}
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Match Manager BeginPlay (NOT SERVER)"));
}
}
So only one mallet
can be the host but it seems that neither != ROLE_AUTHORITY