So I’m seeing some really weird functionality with the isLocallyControlled() function.
While running into some problems (I too quickly set bIsReplicated in the GoKart.cpp to false leading to some crazy shenanigan’s that required a few hours of debugging to get everything going again, but that aside) and in an attempt to solve them I decided to see what isLocallyControlled() returns on different clients/servers.
Autonomous Proxy works pretty much exactly as I expected (returns true)
but when checking it for Authority well… that’s were things went weird.
So in the GoKart.cpp I decided to output it into the log as a bool with the following
// Called every frame
void AGoKart::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
DrawDebugString(GetWorld(), FVector(0, 0, 100), GetEnumText(GetLocalRole()), this, FColor::White, DeltaTime);
DrawDebugString(GetWorld(), FVector(0, 0, 150), GetEnumText(GetRemoteRole()), this, FColor::Red, DeltaTime);
if (GetLocalRole() == ROLE_Authority) {
UE_LOG(LogTemp, Warning, TEXT("isLocallyControlled for %s returns %s"), *GetEnumText(GetLocalRole()), (IsLocallyControlled() ? TEXT("True") : TEXT("False")));
}
}
And here was the result…
So… turns out authority both Is and Isn’t player controlled? I mean it… kind of makes sense in a weird way, but at the same time looking at the isLocallyControlled function in the engine for APawn/AController i can’t imagine a situation where it would return anything other than true, especially in this case cause it’s just returning the GetLocalRole check
bool AController::IsLocalController() const
{
const ENetMode NetMode = GetNetMode();
if (NetMode == NM_Standalone)
{
// Not networked.
return true;
}
if (NetMode == NM_Client && GetLocalRole() == ROLE_AutonomousProxy)
{
// Networked client in control.
return true;
}
if (GetRemoteRole() != ROLE_AutonomousProxy && GetLocalRole() == ROLE_Authority)
{
// Local authority in control.
return true;
}
return false;
}
Anyone have any ideas why it might be doing this?