FTicker continues to run after game stopped

I’m using FTicker to run code in a class that doesn’t extend UObject. This works just fine. However the function doesn’t stop getting called, even if the game is stopped in the editor. It still continues to tick away and give me output in the log.

TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &ConnectionManager::Tick), 1.0f);

Tick function

bool ConnectionManager::Tick(float DeltaTime)
{
	UE_LOG(LogTemp, Warning, TEXT("ConnectionManager::Tick"));
	return true;
}

As far as I can tell the destructor never gets called:

ConnectionManager::~ConnectionManager()
{
	UE_LOG(LogTemp, Warning, TEXT("ConnectionManager::~ConnectionManager"));
	FTicker::GetCoreTicker().RemoveTicker(TickDelegateHandle);
}

I’ve been trying to use other engine examples of FTicker but so far i’m at a loss.

EDIT:
I managed to stop the ticks by creating my own GameInstance and forcing ~ConnectionManager() on the GameInstance Shutdown() function. This seems like the wrong solution though.

Hi,

You say that your ConnectionManager doesn’t extend UObject, but you don’t say how you are managing the lifetime of that object. Is it a direct member of your GameInstance?

If so, perhaps you need to manually create and destroy your ConnectionManager on startup/shutdown, rather than containing it directly:

// MyGameInstance.h
UCLASS()
class UMyGameInstance : public UGameInstance
{
public:
    GENERATED_BODY()

    UMyGameInstance(const FObjectInitializer& ObjectInitializer);

    virtual void Init() override;
    virtual void Shutdown() override;

private:
    ConnectionManager* CM;
};

// MyGameInstance.cpp
UMyGameInstance::UMyGameInstance(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{
    CM = nullptr;
}

void UMyGameInstance::Init()
{
    CM = new ConnectionManager(args);
}

void UMyGameInstance::Shutdown() override
{
    delete CM;
    CM = nullptr;
}

Steve