Hi, since i have installed the Steam layer in my game. When a lcient try to connect to the dedicated server i receive this error PreLogin failure: incompatible_unique_net_id
and the client cannot connect?
Make sure that you’re passing a valid Steam Id to the server’s game mode class’ PreLogin
function. This function gets called every time a client connects to the server and it checks if the UniqueId
parameter passed is “valid”. So what you can do is override the game mode class’ PreLogin
function and in the overridden implementation, call the parent class’ PreLogin
function and make sure to pass a valid steam id for that UniqueId
parameter. Note that this is the source code for the PreLogin
function:
void AGameModeBase::PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage)
{
// Login unique id must match server expected unique id type OR No unique id could mean game doesn't use them
const bool bUniqueIdCheckOk = (!UniqueId.IsValid() || (UniqueId.GetType() == UOnlineEngineInterface::Get()->GetDefaultOnlineSubsystemName()));
if (bUniqueIdCheckOk)
{
ErrorMessage = GameSession->ApproveLogin(Options);
}
else
{
ErrorMessage = TEXT("incompatible_unique_net_id");
}
FGameModeEvents::GameModePreLoginEvent.Broadcast(this, UniqueId, ErrorMessage);
}
And this is what it would look like if you overrode the function:
void AYourGameMode::PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage)
{
const FString& SteamId = UGameplayStatics::ParseOption(Options, "SteamId");
Super::PreLogin(Options, Address, SteamId, ErrorMessage);
}
In this case, clients would pass an option named “SteamId” and this would be used for the UniqueId
parameter when calling Super::PreLogin
Assuming you are connecting via raw IP and have the default NetDriverDefinitions for both sides and no PacketHandlerComponents or SteamNetDriver, the solution I found was to remove a line from PendingNetGame.cpp
//Connection->PlayerId = LocalPlayer->GetPreferredUniqueNetId();
WARNING: I have zero clue what other ramifications there are having a default PlayerId, but that seems to be whats happening if you run the game via editor or run the game without the steam client running. Also the id being passed up before was simply Steam : DisplayName which is therefore not a unique value anyway.
When the server sends and ErrorMessage to fail the login attempt. Where on the client-side will that error message be received? (Which function?)