Hi all,
I’ve been curious about how to detect wether or not a Client is master or not of a character. (ROLE_AutonomousProxy in unreal if I’ve understood well).
I’m taking directly the ThirdPerson sample project given by unreal and just adding some debug display in the tick function:
void ATestReplicationCharacter::Tick(float _fDt)
{
Super::Tick(_fDt);
FString cRole = FString::FromInt((int)this->Role);
FString cRemoteRole = FString::FromInt((int)this->GetRemoteRole());
FString cText = "character => " + this->GetName() + " role : " + cRole + " remote role : " + cRemoteRole;
AController* controller = this->GetController();
if (controller != nullptr)
{
cRole = FString::FromInt((int)controller->Role);
cRemoteRole = FString::FromInt((int)controller->GetRemoteRole());
cText += " | controller => role : " + cRole + "remote role : " + cRemoteRole;
}
GEngine->AddOnScreenDebugMessage(-1, 0.f, FColor::Yellow, cText);
}
nothing fancy here just getting the character and displaying the role and RemoteRole then try getting its controller and do the same.
now I’m deleting the instanciated the third person character from the sample map to get a normal spawning on all machine.
FYI: setting 2 players and no dedicated server.
and I got that :
the line are read from bottom to top
we can see the 2 characters of the 1st client (who is the host) then the 2 on the 2nd client.
the first line say that the character C_4 has Role = 3(authority) and remoteRole = 2 (autonomous) but its controller has role = 3(authority) and remoteRole = 1(Simulated). It’s basically saying that both of the two characters are driven by the clients whereas one of the controller say the inverse (which is true => C_4 should be Role=authority and remoteRole = 1(Simulated) also)
I found it disturbing because we can find the replicated version of this character (C_7) on the third line (bottom to top again) on the client but this time we have role == 1 (Simulated) and remoteRole = 3 (authority). I think this line is totally normal since this character is the one controlled by the other client (who is the host).
so my questions are :
Why do I have a difference in term of net role between character and its controller (in this case) ?
How can we end in a situation where an actor doesn’t have opposite role (role <=> remoteRole) on a two machines network ? (C_4 netRoles should be the inverse of C_7 netRole, isn’t it ?)
Is this a bug ? Something to setup in the spawn process ?
I know that I can still rely on the IsLocalController() but I was just curious to see if something is wrong here before taking a step forward
N.B. : this is not happening if :
- I let the character instance in the map
- I use a dedicated server
Thanks a lot for your answer !