Is there any way to get the number of replicas?

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.

int32 PawnsOnClient = World->GetNumPawns();
int32 ControllersOnServer =  World->GetNumControllers();

The functions are deprecated.

Any other alternative is welcome.


I am probably going to say something stupid, I’m not really good wit c++. Have you tried using get all actors of class?

1 Like

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 :heart:

Call to server and let server count how much call was.

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.

Last thing on my mind is game state (or player state).

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.

No , I mean communicate through them.

As far as I know it is not possible because they have not authority…

When I thought I had a solution…

I think Epic hates me :sob:

Is it look like this? Red players, black “replicas”. In 4 different worlds?

Yes, exactly, that’s right.

In this case your count should be 4 or 16? or 12?

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.

The players themselves should have authority over their own character. Is it?
If so let player character execute the code.

It works like this:

But replicas are just a copy of your character… (A replica that doesn’t update if you make changes before it exists)

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.

1 Like

I’m going to try that. Thanks for your comment :heart:

1 Like

I should’ve asked this from the start:
Are these replicas being spawned by you? Or is it handled by the engine?

I spawn only one player’s pawn ( On the server). The replicas are generated by the engine in the other players’ worlds.

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.