How to compare two FUniqueNetId properly?

The Compare method is protected, you must use the equality/inequality operators.

friend bool operator==(const FUniqueNetId& Lhs, const FUniqueNetId& Rhs)
{
	return Lhs.Compare(Rhs);
}

friend bool operator!=(const FUniqueNetId& Lhs, const FUniqueNetId& Rhs)
{
	return !Lhs.Compare(Rhs);
}

Those operators acts on references. So you have to do something like this:

const FUniqueNetId& LocalPlayerUniqueIdRef = *(GetGameInstance()->GetPrimaryPlayerUniqueId().Get());
const FUniqueNetId& InPlayerUniqueIdRef = *(PlayerState->UniqueId.GetUniqueNetId().Get());

bool bIsSamePlayerId = LocalPlayerUniqueIdRef == InPlayerUniqueIdRef;
1 Like