RealDocs

AActor::GetNetMode

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public

Description

Returns the current network mode (dedicated server, listen server, client, or standalone). Use this to branch logic based on how the game is running.

Caveats & Gotchas

  • In non-editor builds, prefer IsNetMode() over GetNetMode() == X — the compiler can eliminate branches for modes that can't exist in a given build target (e.g., no client code in a server build).
  • Returns NM_Standalone in PIE single-player sessions — don't mistake this for a shipping standalone build.
  • Inlined via InternalGetNetMode(); do not cache the return value across frames as it can change when the net driver is torn down.

Signature

ENetMode GetNetMode() const

Return Type

ENetMode

Example

Branch between server and client logic C++
void AMyActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    switch (GetNetMode())
    {
    case NM_DedicatedServer:
        RunServerLogic();
        break;
    case NM_Client:
        RunClientLogic();
        break;
    default:
        break;
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.