SubSystem only on server

Hey all, I figured I’d add my solution to this thread. This is for a UWorldSubsystem. It runs only on Dedicated, Standalone, and ListenServer.

Be sure to compile outside the Editor and not use Live Coding for this :slight_smile:

Works in 5.3.1

bool UMyWorldSubsystem::ShouldCreateSubsystem(UObject* Outer) const
{
    // Call super
    if (!Super::ShouldCreateSubsystem(Outer))
    {
        return false;
    }
    
    UWorld* World = Cast<UWorld>(Outer);
    TEnumAsByte<EWorldType::Type> type = World->WorldType;
    bool IsValidType = type != EWorldType::Editor && type != EWorldType::EditorPreview && type != EWorldType::None;    
    if (IsValidType) return World->GetNetMode() < NM_Client;
    return false;
}
2 Likes