RealDocs

UActorComponent::GetNetMode

function Engine Since 4.0
#include "Components/ActorComponent.h"
Access: public Specifiers: const

Description

Returns the network mode of the world this component exists in (dedicated server, listen server, client, or standalone). Prefer IsNetMode() for single-mode checks in optimised builds.

Caveats & Gotchas

  • In non-editor optimised builds the dedicated server check is resolved at compile time via IsRunningDedicatedServer(); calling GetNetMode() frequently in hot paths is therefore cheap on dedicated servers but may add overhead on clients or listen servers.
  • Returns NM_Standalone when there is no owning world or when called in-editor outside of PIE — do not rely on this value for editor utility logic.

Signature

ENetMode GetNetMode() const

Return Type

ENetMode

Example

Branch on net mode inside a component C++
void UMyComponent::SetupForEnvironment()
{
	switch (GetNetMode())
	{
		case NM_DedicatedServer:
			InitServerOnlyData();
			break;
		case NM_Client:
			InitClientOnlyData();
			break;
		default:
			InitStandaloneData();
			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.