How can I detect a connection failure in-game?

Hi,

I was wondering how to detect failure to connect to a game server?

So, Right now as an example I have the following:

GEngine->SetClientTravel(PC->GetWorld(), TEXT("10.0.0.1"), TRAVEL_Absolute);

This will try to connect to a server (on IP 10.0.0.1) but, if it cant connect nothing really happens and I just stay in the current menu.

How can I detect if the connection failed? Is there some kind of event that gets fired? Can I add a hook to do my own logic in case of connection failure?

Thanks!

Hi Dratone,

You can use UEngine::OnNetworkFailure. An example:

GEngine->OnNetworkFailure().AddUObject(this, &MyObject::HandleNetworkFailure);

void MyObject::HandleNetworkFailure(UWorld *World, UNetDriver *NetDriver, ENetworkFailure::Type FailureType, const FString& ErrorString)
{
}

And in case you need the information in Blueprint (think: UI widget), there’s a node on the GameInstance, called “Event NetworkError”.