Distinguish Between Listen Server and Dedicated Server


Is there a way that I can distinguish between a listen server and a dedicated server? (For example I want to spawn particle effects if we are a listen server but not if we are a dedicated server).

Grab this…

In Blueprint there is a macro called CanExecuteCosmeticEvent which simply uses the IsDedicatedServer function.

In C++ you can use

GetNetMode() != NM_DedicatedServer

or if you want to get rid of the code completely on the dedicated server using the preprocessor.

#endif // !UE_SERVER

Thank you very much, perfect answer!

I picked this up somewhere in my searching/learning…

#define NETMODE_WORLD (((GEngine == nullptr) || (GetWorld() == nullptr)) ? TEXT("") \
        : (GEngine->GetNetMode(GetWorld()) == NM_Client) ? TEXT("[Client] ") \
        : (GEngine->GetNetMode(GetWorld()) == NM_ListenServer) ? TEXT("[ListenServer] ") \
        : (GEngine->GetNetMode(GetWorld()) == NM_DedicatedServer) ? TEXT("[DedicatedServer] ") \
        : TEXT("[Standalone] "))

    UE_LOG(<name of your log>, Log, TEXT("%s() NetMode: %s ")
        , TEXT(__FUNCTION__)
        , NETMODE_WORLD);