I have created an RtsPawn which spawns a character on the server and replicates the character to the client. I also have a PlayerController which possess the RtsPawn. Now I want to bind some functions from the spawned character to player input.
The problem that I have is that I do not know when the character is ready on the client. I think I could do it like this:
class AArenaCharacter* OldServerCharacter;
UPROPERTY(ReplicatedUsing=OnRepServerCharacter)
class AArenaCharacter* ServerCharacter;
void RtsPawn::OnRepServerCharacter{
if(OldServerCharacter == nullptr && ServerCharacter != nullptr){
//ServerCharacter just got replicated this first time, client should be ready
}
OldServerCharacter = ServerCharacter;
}
This is a bit ugly, are there other ways to do this? Maybe I could send a ClientRpc from the server with the SpawedCharacter?
Ah yes, it takes time. For this you can really only use the “OnRep” functions. Or you simulate things on the client, like filling the variable on his side
too, so he doesn’t feel the lag.
If you only want to know when the Client Version of the Variable gets the value, you just need to use the OnRep function.
It is called on the client, as soon as the variable got the value that the server set it to. Other things will just be dirty work arounds.