SpawnPrioritySeconds

SpawnPrioritySeconds

#Overview

name: SpawnPrioritySeconds

The value of this variable can be defined or overridden in .ini config files. 4 .ini config files referencing this setting variable.

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of SpawnPrioritySeconds is to control the priority of actor spawning and replication in Unreal Engine’s networking system. It serves as a time-based threshold for determining when newly spawned or recently updated actors should be considered for network replication.

This setting variable is primarily used by the networking subsystem of Unreal Engine, specifically within the NetDriver and its related components. It is utilized in both the base Engine implementation and the Oculus Online Subsystem plugin.

The value of SpawnPrioritySeconds is typically set in configuration files, as indicated by the UPROPERTY(Config) decorator in the UNetDriver class declaration. It can be modified through project settings or config files.

SpawnPrioritySeconds interacts with other timing-related variables in the networking system, such as RelevantTimeout and LastUpdateTime. It is often used in calculations involving GetElapsedTime() to determine priorities for actor replication.

Developers should be aware that:

  1. Setting SpawnPrioritySeconds to 0 is not recommended, as the code includes a safeguard to set it to 1.0 if it’s found to be 0.
  2. This variable directly affects the prioritization of actor spawning and updates across the network, which can impact game performance and network bandwidth usage.

Best practices when using this variable include:

  1. Carefully tuning its value based on the specific needs of your game, considering factors like game type, number of players, and network conditions.
  2. Monitoring its impact on network performance and adjusting as necessary.
  3. Considering its interaction with other networking settings to achieve optimal replication behavior.
  4. Documenting any custom values used in your project to maintain consistency across the development team.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:1638, section: [/Script/OnlineSubsystemUtils.IpNetDriver]

Location: <Workspace>/Engine/Config/BaseEngine.ini:1803, section: [/Script/Engine.DemoNetDriver]

Location: <Workspace>/Engine/Config/BaseEngine.ini:2265, section: [/Script/SteamSockets.SteamSocketsNetDriver]

Location: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Config/BaseWebSocketNetDriver.ini:18, section: [/Script/WebSocketNetworking.WebSocketNetDriver]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemOculus/Source/Private/OculusNetDriver.cpp:64

Scope (from outer to inner):

file
function     bool UOculusNetDriver::InitBase

Source code excerpt:

	}

	if (SpawnPrioritySeconds == 0.0)
	{
		UE_LOG(LogNet, Warning, TEXT("SpawnPrioritySeconds was set to %f"), SpawnPrioritySeconds);
		SpawnPrioritySeconds = 1.0;
	}

	if (RelevantTimeout == 0.0)
	{
		UE_LOG(LogNet, Warning, TEXT("RelevantTimeout was set to %f"), RelevantTimeout);
		RelevantTimeout = 5.0;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:882

Scope (from outer to inner):

file
class        class UNetDriver : public UObject, public FExec

Source code excerpt:

	/** @todo document */
	UPROPERTY(Config)
	float SpawnPrioritySeconds;

	/** @todo document */
	UPROPERTY(Config)
	float RelevantTimeout;

	/** @todo document */

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/DataChannel.cpp:2233

Scope (from outer to inner):

file
function     void UActorChannel::Init

Source code excerpt:


	RelevantTime			= Connection->Driver->GetElapsedTime();
	LastUpdateTime			= Connection->Driver->GetElapsedTime() - Connection->Driver->SpawnPrioritySeconds;
	bForceCompareProperties	= false;
	bActorIsPendingKill		= false;
	CustomTimeDilation		= 1.0f;
}

void UActorChannel::SetClosingFlag()

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/DemoNetDriver.cpp:2063

Scope (from outer to inner):

file
function     void UDemoNetDriver::TickDemoRecordFrame

Source code excerpt:

					if (bDoPrioritizeActors) // implies bDoFindActorChannelEarly is true
					{
						const double LastReplicationTime = Channel ? (GetElapsedTime() - Channel->LastUpdateTime) : SpawnPrioritySeconds;
						float ReplayPriority = 65536.0f * Actor->GetReplayPriority(ViewLocation, ViewDirection, Viewer, ViewTarget, Channel, LastReplicationTime);
						
						if (Actor == ViewTarget)
						{
							ReplayPriority = ReplayPriority * DemoNetDriverRecordingPrivate::CVarDemoViewTargetPriorityScale.GetValueOnAnyThread();
						}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4744

Scope (from outer to inner):

file
function     FActorPriority::FActorPriority

Source code excerpt:

	: ActorInfo(InActorInfo), Channel(InChannel), DestructionInfo(NULL)
{	
	const float Time = Channel ? (InConnection->Driver->GetElapsedTime() - Channel->LastUpdateTime) : InConnection->Driver->SpawnPrioritySeconds;
	// take the highest priority of the viewers on this connection
	Priority = 0;
	for (int32 i = 0; i < Viewers.Num(); i++)
	{
		Priority = FMath::Max<int32>(Priority, FMath::RoundToInt(65536.0f * ActorInfo->Actor->GetNetPriority(Viewers[i].ViewLocation, Viewers[i].ViewDir, Viewers[i].InViewer, Viewers[i].ViewTarget, InChannel, Time, bLowBandwidth)));
	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetDriver.cpp:4761

Scope (from outer to inner):

file
function     FActorPriority::FActorPriority

Source code excerpt:

	for (int32 i = 0; i < Viewers.Num(); i++)
	{
		float Time  = InConnection->Driver->SpawnPrioritySeconds;

		FVector Dir = DestructionInfo->DestroyedPosition - Viewers[i].ViewLocation;
		float DistSq = Dir.SizeSquared();
		
		// adjust priority based on distance and whether actor is in front of viewer
		if ( (Viewers[i].ViewDir | Dir) < 0.f )