I think the actor has spawned into the client world where GameMode doesn’t exist.
It is true that the client has authority if it uses over the actor it has created, but without an instance of GameMode there is no way to communicate with the server.
I tried to replicate a world pointer from the server and it didn’t work.
I also tried to replicate a pointer to GameMode instance and that didn’t work either.
You need to ensure that Replicated Actors are only spawned on the Server so they replicate to the clients.
Replicating pointers of objects that are not replicated won’t work.
You need to give ownership to the client that you want to call the server RPC from. Clients already have ownership of possessed Pawns and their PlayerController but it is possible to SetOwner on any other replicated Actor during spawning or on an existing Actor.
You only need to call SetOwner on the Server just after you spawn the Actor. No need for the client RPC. The Actor Owner could be the Client PlayerController or Pawn or something else that the client already own.
After you have Set the owner by the server you can use the OnRep_Owner callback and when the Owner is valid you are ready to send the Server RPC from the client.
My Actor is the AGameState derived Class… the actor component is a UGameStateComponet… So, there is not controller and there is no pawn… ¿Culd be that the problem?
Just keep in mind that PlayerControllers are only replicated to the owner so you can only replicate variables to that specific Client on the PlayerController and it’s components.
void MyClass::Rep_NotifyToClient()
{
if (Success)
{
APlayerController* PlayerController =
UGameplayStatics::
GetPlayerController(GetWorld(),0);
AGamePlayPlayerController
*GamePlayPlayerController =
Cast<AGamePlayPlayerController>
(PlayerController);
if (!IsValid(GamePlayPlayerController))
{
message::Error(
"GamePlayPlayerController is NULL");
return;
}
GamePlayPlayerController->
NotifyReplicationToServer();
}
}
I can finally know when the data is available on the client side and synchronize things from the server. Especially at the beginning of the game and when loading the map.
Thank you very much for your help.
Really Really very much appreciated.