I’m trying to get the HandleNetworkFailure event to work in my Game Instance in C++. I’m doing this because the Event Network Error node in blueprints is missing an output for the Error String for some odd reason.
The idea is that it would print Custom network error event works! to the server log when the event is fired. That way I’ll know it works and I can take it from there.
Everything compiles fine, but nothing seems to happen - nothing is printed to the log.
I’m trying to override a base implementation but when I add override; at the end I get this error during compilation:
Severity Code Description Project File Line Suppression State
Error C3668 'UMyGameInstance::HandleNetworkFailure': method with override specifier 'override' did not override any base class methods
I’m new to C++ and I have no idea what that means, but I think that this event can’t be overridden.
Would you be kind enough to show me how to override UEngine::HandleNetworkFailure, please? I’m new to C++ and I don’t know what to write in the .h file to get it to work and I’m sure that a lot of others that’ll be looking for this in the future won’t either.
Thanks a lot! I tried to do exactly what you wrote even before I started this thread but it didn’t work because I don’t know where to put GEngine->OnNetworkFailure().AddUObject(this, &UMyClass::NetworkFailureHappened);
I tried to put it in the .cpp file where you wrote // do some logic but that didn’t work. Where should I put that line?
It has to be executed in order to work. You can move all this logic to your game instance, and register this in Init() method of your game instance. Works for me, just did some logic about that 5 mins ago :).
Since this is error handling that can happen at any time of the app (in game, looby… etc), maybe it’s best to put it in the GameInstance, so it’s alive while the game is alive.
So your game instance .h file:
Alright everyone in the future, I’ve gotten it to work with the help of the kind people above. This is how your .h file should look (Change: MyGameInstance & MYPROJECT to what corresponds to your own project).
#pragma once
#include "Engine/GameInstance.h"
#include "CoreMinimal.h"
#include "Engine/Engine.h"
#include "MyGameInstance.generated.h"
UCLASS()
class MYPROJECT_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
virtual void Init() override;
// Our custom OnNetworkFailure event which also returns the error string.
UFUNCTION(BlueprintNativeEvent)
void NetworkFailureHappened(UWorld* InWorld, UNetDriver* NetDriver, ENetworkFailure::Type FailureType, const FString& ErrorString);
};
Hello I tried your solution but I am getting this error when I am trying to compile I didn’t have it before
1>[1/4] Compile EOSgameInstance.cpp
1>C:\DFC\Source\DFCFromScratch\Private\EOSgameInstance.cpp(84): warning C4996: 'FTicker': Please use thread-safe FTSTicker, see the migration guide in the code comment above Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
1>C:\DFC\Source\DFCFromScratch\Private\EOSgameInstance.cpp(84): warning C4996: 'FTicker::AddTicker': Please use thread-safe FTSTicker, see the migration guide in the code comment above Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
1>C:\DFC\Source\DFCFromScratch\Private\EOSgameInstance.cpp(161): warning C4996: 'FTicker': Please use thread-safe FTSTicker, see the migration guide in the code comment above Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
1>C:\DFC\Source\DFCFromScratch\Private\EOSgameInstance.cpp(161): warning C4996: 'FTicker::RemoveTicker': Please use thread-safe FTSTicker, see the migration guide in the code comment above Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
1>[2/4] Link UnrealEditor-DFCFromScratch.lib