I would like to implement a handler for the event FOnNetworkFailure
, this is my code:
// Game Instance Subsystem initialization
void UMyGISubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
GEngine->OnNetworkFailure().AddUObject(this, &UMyGISubsystem::HandleNetworkFailure);
}
void UMyGISubsystem::HandleNetworkFailure(UWorld* World, UNetDriver* InNetDriver, ENetworkFailure::Type FailureType,
const FString& StrError)
{
UE_LOG(LogNet, Error, TEXT("%s: NetworkFailure: %s"), *GetFullName(), *StrError)
LeaveSession();
}
I can produce a network failure by calling GameSession->KickPlayer()
from within the GameMode
, but I never see my log output, nor does my session get destroyed.
This is weird, as there does seem to happen stuff regarding Network Failure in my logs:
[2022.11.01-20.40.00:026][350]LogNet: UChannel::ReceivedSequencedBunch: Bunch.bClose == true. ChIndex == 0. Calling ConditionalCleanUp.
[2022.11.01-20.40.00:026][350]LogNet: UChannel::CleanUp: ChIndex == 0. Closing connection. [UChannel] ChIndex: 0, Closing: 0 [UNetConnection] RemoteAddr: 192.168.1.7:7777, Name: IpConnection_6, Driver: GameNetDriver IpNetDriver_6, IsServer: NO, PC: BP_MyPlayerController_C_0, Owner: BP_MyPlayerController_C_0, UniqueId: NULL:DESKTOP-4092S33-CAF677394FABED484D8F5691C5B9DC80
[2022.11.01-20.40.00:027][350]LogNet: UNetConnection::Close: [UNetConnection] RemoteAddr: 192.168.1.7:7777, Name: IpConnection_6, Driver: GameNetDriver IpNetDriver_6, IsServer: NO, PC: BP_MyPlayerController_C_0, Owner: BP_MyPlayerController_C_0, UniqueId: NULL:DESKTOP-4092S33-CAF677394FABED484D8F5691C5B9DC80, Channels: 3, Time: 2022.11.01-20.40.00
[2022.11.01-20.40.00:028][350]LogNet: UNetConnection::Close: CloseReason:
[2022.11.01-20.40.00:028][350]LogNet: - Result=ControlChannelClose, ErrorContext="ControlChannelClose"
[2022.11.01-20.40.00:029][350]LogNet: UChannel::Close: Sending CloseBunch. ChIndex == 0. Name: [UChannel] ChIndex: 0, Closing: 0 [UNetConnection] RemoteAddr: 192.168.1.7:7777, Name: IpConnection_6, Driver: GameNetDriver IpNetDriver_6, IsServer: NO, PC: BP_MyPlayerController_C_0, Owner: BP_MyPlayerController_C_0, UniqueId: NULL:DESKTOP-4092S33-CAF677394FABED484D8F5691C5B9DC80
[2022.11.01-20.40.00:029][350]LogNet: Error: UEngine::BroadcastNetworkFailure: FailureType = ConnectionLost, ErrorString = Your connection to the host has been lost., Driver = GameNetDriver IpNetDriver_6
[2022.11.01-20.40.00:030][350]LogNet: Warning: Network Failure: GameNetDriver[ConnectionLost]: Your connection to the host has been lost.
[2022.11.01-20.40.00:030][350]LogNet: NetworkFailure: ConnectionLost, Error: 'Your connection to the host has been lost.'
What, then, is a proper way do deal with some network failure event?