My code compiles fine but crashes when I hit play. I narrowed it down to the line where I add a delegate to a Ticker. Core ticker to be exact. It crashes the editor with a access violation exception.
Any ideas?
Here’s my .h:
class GlobalData;
UCLASS()
class BUILDINGESCAPE_API UBuildingEscapeGameInstance : public UGameInstance
{
GENERATED_BODY()
private:
FDelegateHandle TickerDelegateHandle;
GlobalData* GameGlobalData;
public:
bool Tick(float DeltaSeconds);
virtual void Init() override;
virtual void Shutdown() override;
};
my .cpp which is where the crash happens. If I comment out the line I am adding the delegate it runs fine.
void UBuildingEscapeGameInstance::Init() {
Super::Init();
this->TickerDelegateHandle = FTicker::GetCoreTicker()
.AddTicker(FTickerDelegate::CreateUObject(this, &UBuildingEscapeGameInstance::Tick));
this->GameGlobalData = new GlobalData();
}
bool UBuildingEscapeGameInstance::Tick(float DeltaSeconds) {
UE_LOG(LogTemp, Warning, TEXT("Delta Time: %s"), DeltaSeconds);
return true;
}
void UBuildingEscapeGameInstance::Shutdown() {
delete(GameGlobalData);
FTicker::GetCoreTicker().RemoveTicker(TickerDelegateHandle);
Super::Shutdown();
};