I am trying to count the number of replications of a pawn. But I don’t get it. They are in different worlds, they have no authority, nor are they the client.
I just know that they exist. But I can’t count them.(I know it will be replicated as many times as there are players in the game… but I want to count them anyway).
//------------------------------------------
bool FRoleMode::IsSimulatedProxy(const AActor *Actor)
{
const ENetRole LocalRole =
Actor->GetLocalRole();
return (LocalRole ==
ENetRole::ROLE_SimulatedProxy);
}
//------------------------------------------
bool FRoleMode::IsReplicatedOnClient(const APawn *Pawn) // Execute On Client Side
{
if (!IsValid(Pawn))return false;
return (FRoleMode::IsSimulatedProxy(Pawn)
&& !Pawn->IsLocallyControlled());
}
//------------------------------------------
void AMyComponent::CountReplicas(const APawn *Pawn)
{
if (FRoleMode::IsReplicatedOnClient(Pawn))
{
Count++; //-->I want to count it
}
}
//------------------------------------------
I am executing this in the BeginPlay function of an actor component that is in a pawn.
Maybe there is some API function that does this directly? Or any way to do it?
Thank you so much!!
NOTE: I want to know the number of replicas to start the game… I don’t want to start before the replicas exist.
I can’t compare controllers on the server with pawns on the client.
That only works within the same world. The replicas are in different worlds… I’m going to try to compare controllers on the server with pawns on the client… I don’t know, maybe it will work.
Thanks for your comment
That’s the problem. The replicas cannot communicate with the server. They have not authority. That’s why I can’t replicate the Count variable in my example and count it.
The replicas does not exist in the GameState or PlayerState… They are just a copy in the world, it is like a reflection in a mirror. The problem is that if you make changes before they exist, the changes are not updated in them. For example, if you change the Skin, the replica will not know it.
Yes, but that’s the theory. The reality is that you don’t know what is happening on the other player’s computer. That’s why I want to count it. If any replica does not exist, perhaps there was a problem. I could send an error message or something like that.
This is only true for Remote Procedure Calls (RPC’s). Replicated variables gets replicated eventually if or when the Actor becomes relevant to the client.
Omg, I feel stupid right now. I thought you made some system to make 4 different levels, and the engine didn’t replicate other players so you made it yourself.