I need to use tick on my subsystem, but there seems to be a bug, can anyone confirm if this is true?
I expect the Tick function not to execute while the game is paused but it does. when printing the return value of UGameplayStatics::IsGamePaused(this) within Tick, It keeps switching between true and false, which is odd already, but I did not expect the Tick function to execute at all when the game is paused. What is going on here in the engine? I confirmed that the game is paused and unpaused correctly.
Test Subsystem .h :
#pragma once
#include "Tickable.h"
#include "TestSubsystem.generated.h"
UCLASS()
class UTestSubsystem : public UGameInstanceSubsystem, public FTickableGameObject
{
GENERATED_BODY()
public:
// Begin USubsystem
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
// End USubsystem
// Begin FTickableGameObject
virtual bool IsTickableWhenPaused() const override;
virtual TStatId GetStatId() const override;
virtual void Tick(float DeltaSeconds) override;
// End FTickableGameObject
};
Test Subsystem .cpp :
#pragma once
#include "TestSubsystem.h"
// Begin USubsystem
void UTestSubsystem::Initialize(FSubsystemCollectionBase &Collection) {
Super::Initialize(Collection);
}
void UTestSubsystem::Deinitialize() {
Super::Deinitialize();
}
// End USubsystem
bool UTestSubsystem::IsTickableWhenPaused() const {
return false;
}
TStatId UTestSubsystem::GetStatId() const {
return UObject::GetStatID();
}
void UTestSubsystem::Tick(float DeltaSeconds) {
if (UGameplayStatics::IsGamePaused(this)) {
if (GEngine) { GEngine->AddOnScreenDebugMessage(-1, 4.0, FColor::Red, "TimeSubsystem: PAUSED"); }
}
else {
if (GEngine) { GEngine->AddOnScreenDebugMessage(-1, 4.0, FColor::Green, "TimeSubsystem: NOT PAUSED"); }
}
}