SubSystem only on server

If you are a Game subsystem (you derive from UGameInstanceSubsystem), then ShouldCreateSubsystem will get invoked before the World exists.

Instead, you can query the GameInstance’s WorldContext to see if it is running on a dedicated server via RunAsDedicated. Then use that to decide if you should create your subsystem or not.

bool UMyGameSubsystem::ShouldCreateSubsystem(UObject* Outer) const
{
	// Call super
	if (!Super::ShouldCreateSubsystem(Outer))
	{
		return false;
	}

	// Downcast Outer to a game instance
	const auto Game = static_cast<UGameInstance*>(Outer);

	// If our world context is running as a dedicated server, dont create our instance
	bool ShouldCreate = !Game->GetWorldContext()->RunAsDedicated;

	// Return if we should create this subsystem instance
	return ShouldCreate
}
1 Like