I have a class that does not respond to RPC calls when called from a client. However, there’s no problems when called from the server.
I have a Board object in my level (that is, dragged and dropped into the level) that creates a bunch of Piece objects during its BeginPlay()
call, but only when HasAuthority()
is true
, so the pieces are only created in the server. I can verify that the pieces are being replicated properly in the clients, as they are instantiated and updated correctly whenever a change in the server occurs. bReplicates = true
is set in both Board and Piece.
The function I’m attempting to call is located in the board, the pieces being its callers.
The order of actions is as follows:
- A Piece object calls
ClientSelect()
. -
ClientSelect()
callsServerSelect()
.ServerSelect()
has the macro propertiesReliable, Server, WithValidation
defined. To my understanding, this should delegate the execution from the client to the server. -
ServerSelect_Implementation()
, contained and called in the server callsSelect()
, which contains the selection logic.
Board.h:
void ClientSelect(int32 Row, int32 Col);
UFUNCTION(Reliable, Server, WithValidation)
void ServerSelect(int32 Row, int32 Col);
virtual bool ServerSelect_Validate(int32 Row, int32 Col);
virtual void ServerSelect_Implementation(int32 Row, int32 Col);
Board.cpp:
void Board::ClientSelect(int32 Row, int32 Col)
{
UE_LOG(LogTemp, Warning, TEXT("Client is attempting to select Piece at %d,%d A:%d"), Row, Col, HasAuthority());
ServerSelect(Row, Col);
}
bool Board::ServerSelect_Validate(int32 Row, int32 Col)
{
UE_LOG(LogTemp, Warning, TEXT("Validating"));
return true;
}
void Board::ServerSelect_Implementation(int32 Row, int32 Col)
{
UE_LOG(LogTemp, Warning, TEXT("Server is attempting to select Piece at %d,%d A:%d"), Row, Col, HasAuthority());
if (State == GAME)
{
if (Grid[Row][Col]->Piece == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("Client attempted to select a nonexisting Piece at %d,%d"), Row, Col);
return;
}
AProjectPiece* Piece = Grid[Row][Col]->Piece;
Select(Piece);
}
}
Output from server:
LogTemp:Warning: Client is attempting to select Piece at 6,2 A:1
LogTemp:Warning: Validating
LogTemp:Warning: Server is attempting to select Piece at 6,2 A:1
LogTemp:Warning: Selecting piece at 6,2
Output from client:
LogTemp:Warning: Client is attempting to select Piece at 6,2 A:0
Things I have tried, to no avail:
- Setting
SetOwner(GetWorld->GetFirstPlayerController())
of the board in the server. However, without thisHasAuthority()
already properly returnstrue
when called from the server andfalse
when called from a client. - Moving all of the RPC calls to the Piece objects.