Configure UTickableWorldSubsystem

This subsystem lives along with the world and is initialized and destroyed at the same time. It’s a subclass of UWorldSubsystem, but with a Tick function.

This class is particularly useful for creating a “Game Master” system to manage game events, like spawning enemy waves or handling level transitions.

To use UTickableWorldSubsystem, you need to override the virtual function TStatId GetStatId() const override and call Super::Initialize(Collection) if you override the Initialize function. This will set UTickableWorldSubsystem::bInitialized to true.

If your UTickableWorldSubsystem doesn’t call the Tick function, make sure to call a Super:: function, and check that IsTickable() returns true (which is the default if you haven’t overridden the function).

In my game, I use a UTickableWorldSubsystem in the “arcade” scene to manage the different waves of platoons sent to defeat the player.

// Header
UCLASS()
class THEPATHTOL0_API UL0PlatoonGameMaster : public UTickableWorldSubsystem
{
	GENERATED_BODY()

public:
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;
	virtual void Tick(float DeltaTime) override;

	virtual TStatId GetStatId() const override
	{
		// Used for profiling means (https://docs.unrealengine.com/5.1/en-US/unreal-engine-stats-system-overview/)
		// Some use `return GetStatID()` (mind the upper case on ID) which create a TStatId. I prefer declare my own:
		RETURN_QUICK_DECLARE_CYCLE_STAT(UL0PlatoonGameMaster, STATGROUP_Tickables);
	}
}


// Body

void UL0PlatoonGameMaster::Initialize(FSubsystemCollectionBase& Collection)
{
	Super::Initialize(Collection);
	// Don't forger to call Super::, do the rest of the init here
}

void UL0PlatoonGameMaster::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *