I’m working on a party system. Since I don’t want to create a widget for the local player, I compare unique ids.
The issue is that sometimes the == operator returns false for the same UniqueId. Here’s the code that compares the unique ids.
// PlayerState is of class ALobbyBeaconPlayerState, the UniqueId is a replicated variable.
// Both the PlayerState and the UniqueId is replicated and valid (not null)
TSharedPtr<const FUniqueNetId> LocalPlayerUniqueId = GetGameInstance()->GetPrimaryPlayerUniqueId();
TSharedPtr<const FUniqueNetId> InPlayerUniqueId = PlayerState->UniqueId.GetUniqueNetId();
// This returns false on client side, even though they are the same unique ids (according to logs)
bool bIsLocalPlayer = LocalPlayerUniqueId == InPlayerUniqueId;
// Temp logs
UE_LOG(LogTemp, Warning, TEXT("MyPlayerUniqueId = %s"), *LocalPlayerUniqueId->ToDebugString());
UE_LOG(LogTemp, Warning, TEXT("IncomingUniqueId = %s"), *InPlayerUniqueId->ToDebugString());
UE_LOG(LogTemp, Warning, TEXT("bIsLocalPlayer = %s"), (bIsLocalPlayer ? TEXT("TRUE") : TEXT("FALSE")));
// Relevant logs, client side
// Player 1
LogTemp: Warning: MyPlayerUniqueId = DESKTOP-ODR6QKS-A60BEDB543B30859CE0958A6F8111521
LogTemp: Warning: IncomingUniqueId = DESKTOP-ODR6QKS-834ADD144BEB1CCDD30DB1B941AFD920
LogTemp: Warning: bIsLocalPlayer = FALSE
// Player 2 <-- This is the local player
// The debug string is the same, yet the compare returned false
LogTemp: Warning: MyPlayerUniqueId = DESKTOP-ODR6QKS-A60BEDB543B30859CE0958A6F8111521
LogTemp: Warning: IncomingUniqueId = DESKTOP-ODR6QKS-A60BEDB543B30859CE0958A6F8111521
LogTemp: Warning: bIsLocalPlayer = FALSE
I guess I could compare the string versions as a workaround, but still, I think I’m missing something here. Could it be an issue that the PlayerState’s UniqueId is a FUniqueNetIdRepl, and I’m getting the actual UniqueNetId via UniqueId.GetUniqueNetId()?
Thanks in advance!